From 481cabcdfbe8b74d1d838b94a67bb2076d48c5d0 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 12 Oct 2025 15:44:32 +0000 Subject: [PATCH] Use bun.fmt for JSON escaping instead of manual implementation Addresses CodeRabbit review comment about incomplete JSON escaping. Uses the existing bun.fmt.formatJSONStringUTF8 utility which properly handles all control characters and edge cases. --- src/watcher/WatcherTrace.zig | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/watcher/WatcherTrace.zig b/src/watcher/WatcherTrace.zig index c189d4b8a6..43b61a3c47 100644 --- a/src/watcher/WatcherTrace.zig +++ b/src/watcher/WatcherTrace.zig @@ -46,16 +46,8 @@ pub fn writeEvents(watcher: *Watcher, events: []Watcher.WatchEvent, changed_file writer.print("{d}", .{timestamp}) catch return; writer.writeAll(",\"index\":") catch return; writer.print("{d}", .{event.index}) catch return; - writer.writeAll(",\"path\":\"") catch return; - - // Escape quotes and backslashes in path - for (file_path) |c| { - if (c == '"' or c == '\\') { - writer.writeByte('\\') catch return; - } - writer.writeByte(c) catch return; - } - writer.writeAll("\"") catch return; + writer.writeAll(",\"path\":") catch return; + writer.print("{}", .{bun.fmt.formatJSONStringUTF8(file_path, .{})}) catch return; // Write individual operation flags writer.writeAll(",\"delete\":") catch return; @@ -77,15 +69,7 @@ pub fn writeEvents(watcher: *Watcher, events: []Watcher.WatchEvent, changed_file if (name_opt) |name| { if (!first) writer.writeAll(",") catch return; first = false; - writer.writeAll("\"") catch return; - // Escape quotes and backslashes in filename - for (name) |c| { - if (c == '"' or c == '\\') { - writer.writeByte('\\') catch return; - } - writer.writeByte(c) catch return; - } - writer.writeAll("\"") catch return; + writer.print("{}", .{bun.fmt.formatJSONStringUTF8(name, .{})}) catch return; } } writer.writeAll("]}\n") catch return;