From 93d3278a5a8f0105ea9b289d1c7426f31ad357b6 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 6 Oct 2024 11:33:29 +0300 Subject: [PATCH] v.util: fix handling of spaces before the second argument of `$d(name, value)` (#22420) --- .../checker/tests/run/using_comptime_d_value.vv | 3 +++ vlib/v/util/util.v | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/vlib/v/checker/tests/run/using_comptime_d_value.vv b/vlib/v/checker/tests/run/using_comptime_d_value.vv index 74e1c3298..29a2d7635 100644 --- a/vlib/v/checker/tests/run/using_comptime_d_value.vv +++ b/vlib/v/checker/tests/run/using_comptime_d_value.vv @@ -1,4 +1,7 @@ +// spaces before the second argument, should not affect the outcome of parsing the $d() directive: #flag -I $d('my_flag','flag_value')/xyz +#flag -I $d('my_flag', 'flag_value')/xyz +#flag -I $d('my_flag', 'flag_value')/xyz #include "@VMODROOT/$d('my_include','vlib/v')/tests/project_with_c_code/mod1/c/header.h" const my_f64 = $d('my_f64', 42.0) diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 80fce03e8..4aceccc08 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -165,10 +165,19 @@ pub fn resolve_d_value(compile_values map[string]string, str string) !string { // Next we parse out the default string value // advance past the `,` and the opening `'` in second argument, or ... eat whatever is there - all_parsed += u8(str[i]).ascii_str() - i++ - all_parsed += u8(str[i]).ascii_str() - i++ + for i < str.len { + ch = str[i] + if ch in [` `, `,`] { + i++ + all_parsed += u8(ch).ascii_str() + continue + } + if ch == `'` { + i++ + all_parsed += u8(ch).ascii_str() + } + break + } // Rinse, repeat for the expected default value string ch = u8(`.`) mut d_default_value := '' -- 2.39.5