This commit is contained in:
Jan 2025-11-23 22:57:06 +00:00 committed by GitHub
commit fbc3664e4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 6 deletions

View file

@ -705,10 +705,12 @@ fn expand_variables_cmake(
const key_start = open_pos.target + open_var.len;
const key = result.items[key_start..];
if (key.len == 0) {
return error.MissingKey;
}
const value = values.get(key) orelse return error.MissingValue;
const value = values.get(key) orelse
if (key.len == 0)
.undef
else
return error.MissingValue;
result.shrinkRetainingCapacity(result.items.len - key.len - open_var.len);
switch (value) {
.undef, .defined => {},
@ -909,8 +911,8 @@ test "expand_variables_cmake simple cases" {
// line with misc content is preserved
try testReplaceVariablesCMake(allocator, "no substitution", "no substitution", values);
// empty ${} wrapper leads to an error
try std.testing.expectError(error.MissingKey, testReplaceVariablesCMake(allocator, "${}", "", values));
// empty ${} wrapper is removed
try testReplaceVariablesCMake(allocator, "${}", "", values);
// empty @ sigils are preserved
try testReplaceVariablesCMake(allocator, "@", "@", values);

View file

@ -94,6 +94,9 @@
// test10
// @noval@@stringval@@trueval@@zeroval@
// empty key, removed
// ${}
// no substition
// ${noval}

View file

@ -94,6 +94,9 @@
// test10
// test10
// empty key, removed
//
// no substition
//