diff options
author | 2022-11-15 22:10:09 -0800 | |
---|---|---|
committer | 2022-11-15 22:10:09 -0800 | |
commit | 4f22c39651bf57f929876bd58e83bf0b3156a9d1 (patch) | |
tree | 865689ecb198323d1be79bc2aa30a4522f78af3a | |
parent | 6c01a1191f07b3f2b8ce1ba07bf4eda25ce5e473 (diff) | |
download | bun-4f22c39651bf57f929876bd58e83bf0b3156a9d1.tar.gz bun-4f22c39651bf57f929876bd58e83bf0b3156a9d1.tar.zst bun-4f22c39651bf57f929876bd58e83bf0b3156a9d1.zip |
Handle trailing slash
-rw-r--r-- | src/url.zig | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/url.zig b/src/url.zig index 5a26b3bb1..7ce94cf4f 100644 --- a/src/url.zig +++ b/src/url.zig @@ -225,7 +225,7 @@ pub const URL = struct { const first_at = strings.indexOfChar(base[offset..], '@') orelse 0; const first_colon = strings.indexOfChar(base[offset..], ':') orelse 0; - if (first_at > first_colon and first_at < (strings.indexOfChar(base[offset..], '/') orelse 0)) { + if (first_at > first_colon and first_at < (strings.indexOfChar(base[offset..], '/') orelse std.math.maxInt(u32))) { offset += url.parseUsername(base[offset..]) orelse 0; offset += url.parsePassword(base[offset..]) orelse 0; } @@ -1424,6 +1424,22 @@ test "URL - parse" { try expectString("3000", url.port); try expectString("/@/example", url.path); try expectString("/@/example", url.pathname); + + url = URL.parse("http://admin:password@0.0.0.0:3000"); + try expectString("http", url.protocol); + try expectString("admin", url.username); + try expectString("password", url.password); + try expectString("0.0.0.0:3000", url.host); + try expectString("0.0.0.0", url.hostname); + try expectString("3000", url.port); + + url = URL.parse("http://admin:password@0.0.0.0:3000/"); + try expectString("http", url.protocol); + try expectString("admin", url.username); + try expectString("password", url.password); + try expectString("0.0.0.0:3000", url.host); + try expectString("0.0.0.0", url.hostname); + try expectString("3000", url.port); } test "URL - joinAlloc" { |