| ... | ... | @@ -6,7 +6,6 @@ const unicode_idna = @import("unicode-idna"); |
| 6 | 6 | |
| 7 | 7 | pub const URL = struct { |
| 8 | 8 | href: []const u8, |
| 9 | | scheme: []const u8 = "", |
| 10 | 9 | protocol: []const u8, |
| 11 | 10 | username: []const u8, |
| 12 | 11 | password: []const u8, |
| ... | ... | @@ -164,7 +163,7 @@ pub const URL = struct { |
| 164 | 163 | state = .file; |
| 165 | 164 | } |
| 166 | 165 | // 6. Otherwise, if url is special, base is non-null, and base’s scheme is url’s scheme: |
| 167 | | else if (isSchemeSpecial(href.items(0)) and base != null and std.mem.eql(u8, base.?.scheme, href.items(0))) { |
| 166 | else if (isSchemeSpecial(href.items(0)) and base != null and std.mem.eql(u8, base.?.scheme(), href.items(0))) { |
| 168 | 167 | @panic("TODO"); |
| 169 | 168 | // 1. Assert: base is special (and therefore does not have an opaque path). |
| 170 | 169 | // 2. Set state to special relative or authority state. |
| ... | ... | @@ -237,9 +236,10 @@ pub const URL = struct { |
| 237 | 236 | }, |
| 238 | 237 | .relative => { |
| 239 | 238 | // 1. Assert: base’s scheme is not "file". |
| 240 | | std.debug.assert(!std.mem.eql(u8, base.?.scheme, "file")); |
| 239 | std.debug.assert(!std.mem.eql(u8, base.?.scheme(), "file")); |
| 241 | 240 | // 2. Set url’s scheme to base’s scheme. |
| 242 | | try href.set(0, base.?.scheme); |
| 241 | try href.set(0, base.?.scheme()); |
| 242 | try href.set(1, ":"); |
| 243 | 243 | // 3. If c is U+002F (/), then set state to relative slash state. |
| 244 | 244 | if (c == '/') { |
| 245 | 245 | state = .relative_slash; |
| ... | ... | @@ -482,6 +482,7 @@ pub const URL = struct { |
| 482 | 482 | .file => { |
| 483 | 483 | // 1. Set url’s scheme to "file". |
| 484 | 484 | try href.set(0, "file"); |
| 485 | try href.set(1, ":"); |
| 485 | 486 | // 2. Set url’s host to the empty string. |
| 486 | 487 | href.clear(7); |
| 487 | 488 | hostname_kind = .name; |
| ... | ... | @@ -493,7 +494,7 @@ pub const URL = struct { |
| 493 | 494 | state = .file_slash; |
| 494 | 495 | } |
| 495 | 496 | // 4. Otherwise, if base is non-null and base’s scheme is "file": |
| 496 | | else if (base != null and std.mem.eql(u8, base.?.scheme, "file")) { |
| 497 | else if (base != null and std.mem.eql(u8, base.?.scheme(), "file")) { |
| 497 | 498 | // 1. Set url’s host to base’s host, url’s path to a clone of base’s path, and url’s query to base’s query. |
| 498 | 499 | // host = base.?.host; |
| 499 | 500 | // try path.appendSlice(base.?.path.?); |
| ... | ... | @@ -549,7 +550,7 @@ pub const URL = struct { |
| 549 | 550 | // 2. Otherwise: |
| 550 | 551 | else { |
| 551 | 552 | // 1. If base is non-null and base’s scheme is "file", then: |
| 552 | | if (base != null and std.mem.eql(u8, base.?.scheme, "file")) { |
| 553 | if (base != null and std.mem.eql(u8, base.?.scheme(), "file")) { |
| 553 | 554 | // 1. Set url’s host to base’s host. |
| 554 | 555 | // host = base.?.host; |
| 555 | 556 | // 2. If the code point substring from pointer to the end of input does not start with a Windows drive letter and base’s path[0] is a normalized Windows drive letter, then append base’s path[0] to url’s path. |
| ... | ... | @@ -883,7 +884,11 @@ pub const URL = struct { |
| 883 | 884 | }; |
| 884 | 885 | |
| 885 | 886 | pub fn isSpecial(u: *const URL) bool { |
| 886 | | return isSchemeSpecial(u.scheme); |
| 887 | return isSchemeSpecial(u.scheme()); |
| 888 | } |
| 889 | |
| 890 | pub fn scheme(u: *const URL) []const u8 { |
| 891 | return u.protocol[0 .. u.protocol.len - 1]; |
| 887 | 892 | } |
| 888 | 893 | }; |
| 889 | 894 | |