| ... | @@ -633,6 +633,10 @@ fn expand_variables_cmake( | ... | @@ -633,6 +633,10 @@ fn expand_variables_cmake( |
| 633 | | 633 | |
| 634 | continue :loop; | 634 | continue :loop; |
| 635 | }, | 635 | }, |
| | 636 | '\\' => { |
| | 637 | // backslash is not considered a special character |
| | 638 | continue :loop; |
| | 639 | }, |
| 636 | else => {}, | 640 | else => {}, |
| 637 | } | 641 | } |
| 638 | | 642 | |
| ... | @@ -811,3 +815,23 @@ test "expand_variables_cmake edge cases" { | ... | @@ -811,3 +815,23 @@ test "expand_variables_cmake edge cases" { |
| 811 | try std.testing.expectError(error.InvalidCharacter, testReplaceVariables(allocator, "${str$ing}", "", values)); | 815 | try std.testing.expectError(error.InvalidCharacter, testReplaceVariables(allocator, "${str$ing}", "", values)); |
| 812 | try std.testing.expectError(error.InvalidCharacter, testReplaceVariables(allocator, "${str@ing}", "", values)); | 816 | try std.testing.expectError(error.InvalidCharacter, testReplaceVariables(allocator, "${str@ing}", "", values)); |
| 813 | } | 817 | } |
| | 818 | |
| | 819 | test "expand_variables_cmake escaped characters" { |
| | 820 | const allocator = std.testing.allocator; |
| | 821 | var values = std.StringArrayHashMap(Value).init(allocator); |
| | 822 | defer values.deinit(); |
| | 823 | |
| | 824 | try values.putNoClobber("string", Value{ .string = "text" }); |
| | 825 | |
| | 826 | // backslash is an invalid character for @ lookup |
| | 827 | try testReplaceVariables(allocator, "\\@string\\@", "\\@string\\@", values); |
| | 828 | |
| | 829 | // backslash is preserved, but doesn't affect ${} variable expansion |
| | 830 | try testReplaceVariables(allocator, "\\${string}", "\\text", values); |
| | 831 | |
| | 832 | // backslash breaks ${} opening bracket identification |
| | 833 | try testReplaceVariables(allocator, "$\\{string}", "$\\{string}", values); |
| | 834 | |
| | 835 | // backslash is skipped when checking for invalid characters, yet it mangles the key |
| | 836 | try testReplaceVariables(allocator, "${string\\}", "", values); |
| | 837 | } |