diff options
author | 2023-07-06 16:01:16 -0300 | |
---|---|---|
committer | 2023-07-06 12:01:16 -0700 | |
commit | 95ddfcc4377350b1d604c39c36562bde45fad2a9 (patch) | |
tree | 0140dad024ebf3521a95bfcfee95418050df8198 | |
parent | ee57935260214cbd6f580a756903df7eebe495ef (diff) | |
download | bun-95ddfcc4377350b1d604c39c36562bde45fad2a9.tar.gz bun-95ddfcc4377350b1d604c39c36562bde45fad2a9.tar.zst bun-95ddfcc4377350b1d604c39c36562bde45fad2a9.zip |
fix query without slash (#3547)
-rw-r--r-- | src/url.zig | 20 | ||||
-rw-r--r-- | test/js/web/fetch/fetch.test.ts | 4 |
2 files changed, 14 insertions, 10 deletions
diff --git a/src/url.zig b/src/url.zig index 66c4ff015..af13b139c 100644 --- a/src/url.zig +++ b/src/url.zig @@ -348,8 +348,8 @@ pub const URL = struct { url.username = str[0..i]; return i + 1; }, - // if we reach a slash, there's no username - '/' => { + // if we reach a slash or "?", there's no username + '?', '/' => { return null; }, else => {}, @@ -374,8 +374,8 @@ pub const URL = struct { if (Environment.allow_assert) std.debug.assert(str[i..].len < 2 or std.mem.readIntNative(u16, str[i..][0..2]) != std.mem.readIntNative(u16, "//")); return i + 1; }, - // if we reach a slash, there's no password - '/' => { + // if we reach a slash or "?", there's no password + '?', '/' => { return null; }, else => {}, @@ -402,8 +402,8 @@ pub const URL = struct { ipv6_i = if (ipv6_i == null and str[i] == ']') i else ipv6_i; colon_i = if (ipv6_i != null and colon_i == null and str[i] == ':') i else colon_i; switch (str[i]) { - // alright, we found the slash - '/' => { + // alright, we found the slash or "?" + '?', '/' => { break; }, else => {}, @@ -421,8 +421,8 @@ pub const URL = struct { } } else { - // look for the first "/" - // if we have a slash, anything before that is the host + // look for the first "/" or "?" + // if we have a slash or "?", anything before that is the host // anything before the colon is the hostname // anything after the colon but before the slash is the port // the origin is the scheme before the slash @@ -432,8 +432,8 @@ pub const URL = struct { colon_i = if (colon_i == null and str[i] == ':') i else colon_i; switch (str[i]) { - // alright, we found the slash - '/' => { + // alright, we found the slash or "?" + '?', '/' => { break; }, else => {}, diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts index 6b87cc613..768818420 100644 --- a/test/js/web/fetch/fetch.test.ts +++ b/test/js/web/fetch/fetch.test.ts @@ -1175,6 +1175,10 @@ it("#2794", () => { expect(typeof Bun.fetch.bind).toBe("function"); }); +it("#3545", () => { + expect(() => fetch("http://example.com?a=b")).not.toThrow(); +}); + it("invalid header doesnt crash", () => { expect(() => fetch("http://example.com", { |