diff --git a/url.zig b/url.zig index 692cccce952f25966c7a0bf146ac8d9e4d4033cd..28e76d76e61a61be6f0324952d5e75e9ae548a61 100644 --- a/url.zig +++ b/url.zig @@ -536,8 +536,8 @@ pub const URL = struct { c = inputl.items[i]; // 1. If state override is not given and buffer is a Windows drive letter, file-invalid-Windows-drive-letter-host validation error, set state to path state. // > This is a (platform-independent) Windows drive letter quirk. buffer is not reset here and instead used in the path state. - if (builtin.target.os.tag == .windows) { - @compileError("TODO"); + if (state_override == null and isWindowsDriveLetter(buffer.items)) { + state = .path; } // 2. Otherwise, if buffer is the empty string, then: else if (buffer.items.len == 0) { @@ -631,10 +631,12 @@ pub const URL = struct { // @panic("TODO"); } // 4. Otherwise, if buffer is not a single-dot URL path segment, then: - else if (isSingleDotPathSeg(buffer.items)) { + else if (!isSingleDotPathSeg(buffer.items)) { // 1. If url’s scheme is "file", url’s path is empty, and buffer is a Windows drive letter, then replace the second code point in buffer with U+003A (:). // > This is a (platform-independent) Windows drive letter quirk. - if (builtin.target.os.tag == .windows) @compileError("TODO"); + if (std.mem.eql(u8, scheme.items, "file") and path.items.len == 0 and isWindowsDriveLetter(buffer.items)) { + buffer.items[1] = ':'; + } // 2. Append buffer to url’s path. try path.appendSlice(buffer.items); } @@ -835,6 +837,14 @@ fn isSingleDotPathSeg(segment: []const u8) bool { return false; } +/// https://url.spec.whatwg.org/#windows-drive-letter +fn isWindowsDriveLetter(buffer: []const u8) bool { + if (buffer.len != 2) return false; + if (!std.ascii.isAlphabetic(buffer[0])) return false; + if (!(buffer[1] == ':' or buffer[1] == '|')) return false; + return true; +} + /// https://url.spec.whatwg.org/#concept-host-parser fn parseHost(allocator: std.mem.Allocator, input: []u8, isOpaque: bool) !URL.Host { // 1. If input starts with U+005B ([), then: