Skip to content

Commit 075a799

Browse files
author
🕵️ Detective build.zig.zon
committed
🐛 Fix escaping quotes format bug
1 parent a66ff11 commit 075a799

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/lib.zig

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ pub fn format(comptime fmt: []const u8) []const u8 {
3333
// Find next '{' or '}' or end of string
3434
inline while (i < fmt.len and fmt[i] != '{' and fmt[i] != '}') : (i += 1) {}
3535

36-
// Append text up to the next control character
37-
if (start_index != i) {
38-
output = output ++ fmt[start_index..i];
39-
}
40-
4136
// Handle escaped braces '{{' or '}}'
4237
if (i + 1 < fmt.len and fmt[i + 1] == fmt[i]) {
43-
output = output ++ fmt[i .. i + 1]; // Append a single brace
4438
i += 2; // Skip both braces
39+
}
40+
41+
// Append text up to the next control character
42+
if (start_index != i) {
43+
output = output ++ fmt[start_index..i];
4544
continue;
4645
}
4746

src/tests.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test "format - Background color and reset" {
3030
test "format - Escaped braces" {
3131
const escaped_braces = chroma.format("{{This}} is {green}green.");
3232

33-
const expected = "{" ++ "This" ++ "} is " ++ COLOR_OPEN ++ "32m" ++ "green." ++ RESET;
33+
const expected = "{{" ++ "This" ++ "}} is " ++ COLOR_OPEN ++ "32m" ++ "green." ++ RESET;
3434
try std.testing.expectEqualStrings(expected, escaped_braces);
3535
}
3636

0 commit comments

Comments
 (0)