From e004eb3d86a07486fdc86706488cbc0a5e77ecb0 Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Sun, 10 Mar 2024 17:01:41 +0000 Subject: [PATCH] Fix routes.zig Windows paths Use `std.zig.pstringEscape` to correctly escape a string for setting as a Zig string. This should catch any potential issue with escaping strings. --- src/GenerateRoutes.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/GenerateRoutes.zig b/src/GenerateRoutes.zig index 3b3636f..613b2a2 100644 --- a/src/GenerateRoutes.zig +++ b/src/GenerateRoutes.zig @@ -437,9 +437,12 @@ fn parseFunction( } } + const full_path = try std.fs.path.join(self.allocator, &[_][]const u8{ "src", "app", "views", path }); + defer self.allocator.free(full_path); + return .{ .name = function_name, - .path = try std.fs.path.join(self.allocator, &[_][]const u8{ "src", "app", "views", path }), + .path = try escapeString(self.allocator, full_path), .args = try self.allocator.dupe(Arg, args.items), .source = try self.allocator.dupe(u8, source), .params = std.ArrayList([]const u8).init(self.allocator), @@ -484,3 +487,13 @@ fn isActionFunctionName(name: []const u8) bool { return false; } + +fn escapeString(allocator: std.mem.Allocator, input: []const u8) ![]const u8 { + var buf = std.ArrayList(u8).init(allocator); + defer buf.deinit(); + const writer = buf.writer(); + + try std.zig.stringEscape(input, "", .{}, writer); + + return try allocator.dupe(u8, buf.items); +}