From 22e8b0fe27c2b6f1fb9b76cf4cd094980ae5e77f Mon Sep 17 00:00:00 2001 From: gechandesu <47027335+gechandesu@users.noreply.github.com> Date: Sun, 14 Jun 2026 16:38:10 +0300 Subject: [PATCH] flag: fix help text generation for xdocs containing colons (#27454) --- vlib/flag/flag_to.v | 4 ++-- vlib/flag/flag_to_doc_test.v | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/vlib/flag/flag_to.v b/vlib/flag/flag_to.v index de67b1066..7aa51d26c 100644 --- a/vlib/flag/flag_to.v +++ b/vlib/flag/flag_to.v @@ -312,8 +312,8 @@ fn (fm FlagMapper) get_struct_info[T]() !StructInfo { for attr in field.attrs { trace_println('\tattribute: "${attr}"') if attr.contains(':') { - split := attr.split(':') - attrs[split[0].trim_space()] = normalize_attr_value(split[1]) + attr_name, attr_value := attr.split_once(':') or { '', '' } + attrs[attr_name.trim_space()] = normalize_attr_value(attr_value) } else { attrs[attr.trim(' ')] = 'true' } diff --git a/vlib/flag/flag_to_doc_test.v b/vlib/flag/flag_to_doc_test.v index 1299b3cd3..4de7b892d 100644 --- a/vlib/flag/flag_to_doc_test.v +++ b/vlib/flag/flag_to_doc_test.v @@ -193,3 +193,16 @@ Footer content' fields: unsafe { field_docs } )! == doc5 } + +struct DocTestXDoc { + dim int @[xdoc: 'dimensions, one of: 1, 2, 3.'] +} + +fn test_to_doc_with_xdoc_containing_colon() { + expected := ' +Options: + --dim dimensions, one of: 1, 2, 3.' + + help := flag.to_doc[DocTestXDoc]()! + assert help == expected +} -- 2.39.5