Merge pull request #88 from drsneed/main

Fix nested paths in public folder on windows
This commit is contained in:
bobf 2024-06-12 17:53:42 +01:00 committed by GitHub
commit 7805dd3cfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -598,17 +598,20 @@ fn matchPublicContent(self: *Server, request: *jetzig.http.Request) !?StaticReso
var walker = try iterable_dir.walk(request.allocator); var walker = try iterable_dir.walk(request.allocator);
defer walker.deinit(); defer walker.deinit();
var path_buffer: [256]u8 = undefined;
while (try walker.next()) |file| { while (try walker.next()) |file| {
if (file.kind != .file) continue; if (file.kind != .file) continue;
const file_path = if (builtin.os.tag == .windows) blk: {
if (std.mem.eql(u8, file.path, request.path.file_path[1..])) { _ = std.mem.replace(u8, file.path, std.fs.path.sep_str_windows, std.fs.path.sep_str_posix, &path_buffer);
break :blk path_buffer[0..file.path.len];
} else file.path;
if (std.mem.eql(u8, file_path, request.path.file_path[1..])) {
const content = try iterable_dir.readFileAlloc( const content = try iterable_dir.readFileAlloc(
request.allocator, request.allocator,
file.path, file_path,
jetzig.config.get(usize, "max_bytes_public_content"), jetzig.config.get(usize, "max_bytes_public_content"),
); );
const extension = std.fs.path.extension(file.path); const extension = std.fs.path.extension(file_path);
const mime_type = if (self.mime_map.get(extension)) |mime| mime else "application/octet-stream"; const mime_type = if (self.mime_map.get(extension)) |mime| mime else "application/octet-stream";
return .{ return .{
.content = content, .content = content,