Merge pull request #20 from jetzig-framework/fix-routes-windows-paths

Fix routes.zig Windows paths
This commit is contained in:
bobf 2024-03-10 17:02:56 +00:00 committed by GitHub
commit 0713062f74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}