Merge pull request #35 from alexnask/better_path_handling

Maintain case when making a URI from a path
This commit is contained in:
Auguste Rame 2020-05-15 08:48:10 -04:00 committed by GitHub
commit 761c277ccc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -634,7 +634,12 @@ pub fn main() anyerror!void {
} }
defer std.json.parseFree(Config, config, config_parse_options); defer std.json.parseFree(Config, config, config_parse_options);
// @TODO Check is_absolute if (config.zig_lib_path != null and !std.fs.path.isAbsolute(config.zig_lib_path.?)) {
std.debug.warn("zig library path is not absolute, defaulting to null.\n", .{});
allocator.free(config.zig_lib_path.?);
config.zig_lib_path = null;
}
try document_store.init(allocator, config.zig_lib_path); try document_store.init(allocator, config.zig_lib_path);
defer document_store.deinit(); defer document_store.deinit();

View File

@ -24,7 +24,17 @@ pub fn fromPath(allocator: *std.mem.Allocator, path: []const u8) ![]const u8 {
try buf.append('%'); try buf.append('%');
try std.fmt.format(out_stream, "{X}", .{char}); try std.fmt.format(out_stream, "{X}", .{char});
} else { } else {
try buf.append(std.ascii.toLower(char)); try buf.append(char);
}
}
// On windows, we need to lowercase the drive name.
if (std.builtin.os.tag == .windows) {
if (buf.items.len > prefix.len + 1 and
std.ascii.isAlpha(buf.items[prefix.len]) and
std.mem.startsWith(u8, buf.items[prefix.len + 1 ..], "%3A"))
{
buf.items[prefix.len] = std.ascii.toLower(buf.items[prefix.len]);
} }
} }