mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-13 23:46:16 +01:00
Add escaped character processing
This commit is contained in:
parent
0307f87715
commit
3e6f07e617
3 changed files with 34 additions and 0 deletions
|
|
@ -633,6 +633,10 @@ fn expand_variables_cmake(
|
|||
|
||||
continue :loop;
|
||||
},
|
||||
'\\' => {
|
||||
// backslash is not considered a special character
|
||||
continue :loop;
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
|
||||
|
|
@ -811,3 +815,23 @@ test "expand_variables_cmake edge cases" {
|
|||
try std.testing.expectError(error.InvalidCharacter, testReplaceVariables(allocator, "${str$ing}", "", values));
|
||||
try std.testing.expectError(error.InvalidCharacter, testReplaceVariables(allocator, "${str@ing}", "", values));
|
||||
}
|
||||
|
||||
test "expand_variables_cmake escaped characters" {
|
||||
const allocator = std.testing.allocator;
|
||||
var values = std.StringArrayHashMap(Value).init(allocator);
|
||||
defer values.deinit();
|
||||
|
||||
try values.putNoClobber("string", Value{ .string = "text" });
|
||||
|
||||
// backslash is an invalid character for @ lookup
|
||||
try testReplaceVariables(allocator, "\\@string\\@", "\\@string\\@", values);
|
||||
|
||||
// backslash is preserved, but doesn't affect ${} variable expansion
|
||||
try testReplaceVariables(allocator, "\\${string}", "\\text", values);
|
||||
|
||||
// backslash breaks ${} opening bracket identification
|
||||
try testReplaceVariables(allocator, "$\\{string}", "$\\{string}", values);
|
||||
|
||||
// backslash is skipped when checking for invalid characters, yet it mangles the key
|
||||
try testReplaceVariables(allocator, "${string\\}", "", values);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,3 +28,8 @@
|
|||
// becomes `empty`
|
||||
#define
|
||||
#define
|
||||
|
||||
#define \@STRING_VAR\@
|
||||
#define \${STRING}
|
||||
#define $\{STRING_VAR}
|
||||
#define
|
||||
|
|
|
|||
|
|
@ -28,3 +28,8 @@
|
|||
// becomes `empty`
|
||||
#define ${${STRING_VAR}}
|
||||
#define ${@STRING_VAR@}
|
||||
|
||||
#define \@STRING_VAR\@
|
||||
#define \${STRING_VAR}
|
||||
#define $\{STRING_VAR}
|
||||
#define ${STRING_VAR\}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue