From 5ff4d7127d1036cfec98407a4e54e141a45a8989 Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Sun, 10 Mar 2024 17:08:00 +0000 Subject: [PATCH] Fix Windows paths again Previous fix did not work, `@import` expects forward slashes so escaping backslashes doesn't help. Replace `\` with `/` instead. --- src/GenerateRoutes.zig | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/GenerateRoutes.zig b/src/GenerateRoutes.zig index 613b2a2..c8b3033 100644 --- a/src/GenerateRoutes.zig +++ b/src/GenerateRoutes.zig @@ -186,12 +186,16 @@ fn writeRoute(self: *Self, writer: std.ArrayList(u8).Writer, route: Function) !v try params_writer.writeAll(".{}"); } + const module_path = try self.allocator.dupe(u8, route.path); + defer self.allocator.free(module_path); + std.mem.replaceScalar(u8, module_path, '\\', '/'); + const output = try std.fmt.allocPrint(self.allocator, output_template, .{ full_name, route.name, uri_path, full_name, - route.path, + module_path, route.name, params_buf.items, }); @@ -437,12 +441,9 @@ 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 escapeString(self.allocator, full_path), + .path = try std.fs.path.join(self.allocator, &[_][]const u8{ "src", "app", "views", path }), .args = try self.allocator.dupe(Arg, args.items), .source = try self.allocator.dupe(u8, source), .params = std.ArrayList([]const u8).init(self.allocator), @@ -487,13 +488,3 @@ 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); -}