authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-22 02:58:24 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-22 02:58:24 -08:00
loge97379550ac5ee94c0369427ed69bc8f764e2261
tree9e26d1ec012addf25e9786caf94de9ed452a6918
parent414b5e83d976b2caf11f72f089fff16cdd9f45ad

└─ run test 542 passed


1 files changed, 14 insertions(+), 4 deletions(-)

url.zig+14-4
...@@ -536,8 +536,8 @@ pub const URL = struct {...@@ -536,8 +536,8 @@ pub const URL = struct {
536 c = inputl.items[i];536 c = inputl.items[i];
537 // 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.537 // 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.
538 // > This is a (platform-independent) Windows drive letter quirk. buffer is not reset here and instead used in the path state.538 // > This is a (platform-independent) Windows drive letter quirk. buffer is not reset here and instead used in the path state.
539 if (builtin.target.os.tag == .windows) {539 if (state_override == null and isWindowsDriveLetter(buffer.items)) {
540 @compileError("TODO");540 state = .path;
541 }541 }
542 // 2. Otherwise, if buffer is the empty string, then:542 // 2. Otherwise, if buffer is the empty string, then:
543 else if (buffer.items.len == 0) {543 else if (buffer.items.len == 0) {
...@@ -631,10 +631,12 @@ pub const URL = struct {...@@ -631,10 +631,12 @@ pub const URL = struct {
631 // @panic("TODO");631 // @panic("TODO");
632 }632 }
633 // 4. Otherwise, if buffer is not a single-dot URL path segment, then:633 // 4. Otherwise, if buffer is not a single-dot URL path segment, then:
634 else if (isSingleDotPathSeg(buffer.items)) {634 else if (!isSingleDotPathSeg(buffer.items)) {
635 // 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 (:).635 // 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 (:).
636 // > This is a (platform-independent) Windows drive letter quirk.636 // > This is a (platform-independent) Windows drive letter quirk.
637 if (builtin.target.os.tag == .windows) @compileError("TODO");637 if (std.mem.eql(u8, scheme.items, "file") and path.items.len == 0 and isWindowsDriveLetter(buffer.items)) {
638 buffer.items[1] = ':';
639 }
638 // 2. Append buffer to url’s path.640 // 2. Append buffer to url’s path.
639 try path.appendSlice(buffer.items);641 try path.appendSlice(buffer.items);
640 }642 }
...@@ -835,6 +837,14 @@ fn isSingleDotPathSeg(segment: []const u8) bool {...@@ -835,6 +837,14 @@ fn isSingleDotPathSeg(segment: []const u8) bool {
835 return false;837 return false;
836}838}
837839
840/// https://url.spec.whatwg.org/#windows-drive-letter
841fn isWindowsDriveLetter(buffer: []const u8) bool {
842 if (buffer.len != 2) return false;
843 if (!std.ascii.isAlphabetic(buffer[0])) return false;
844 if (!(buffer[1] == ':' or buffer[1] == '|')) return false;
845 return true;
846}
847
838/// https://url.spec.whatwg.org/#concept-host-parser848/// https://url.spec.whatwg.org/#concept-host-parser
839fn parseHost(allocator: std.mem.Allocator, input: []u8, isOpaque: bool) !URL.Host {849fn parseHost(allocator: std.mem.Allocator, input: []u8, isOpaque: bool) !URL.Host {
840 // 1. If input starts with U+005B ([), then:850 // 1. If input starts with U+005B ([), then: