aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-09-21 14:34:00 +0800
committerGravatar GitHub <noreply@github.com> 2023-09-20 23:34:00 -0700
commitb00588e98cc4ab5254dca1c6e69829de6e1fd993 (patch)
tree52acb1e6e21f3fb97909a89b140a63c1eacf9dbc /src
parentac19c7c62e3a151251ebaa8aef2f32f7b61808f0 (diff)
downloadbun-b00588e98cc4ab5254dca1c6e69829de6e1fd993.tar.gz
bun-b00588e98cc4ab5254dca1c6e69829de6e1fd993.tar.zst
bun-b00588e98cc4ab5254dca1c6e69829de6e1fd993.zip
fix(fetch): fix redirect in relative path location. (#5781)
* fix(fetch): fix redirect in relative path location. * fix utf-8 encoding * use server.reload * check buf size * add RedirectURLTooLong test
Diffstat (limited to 'src')
-rw-r--r--src/http_client_async.zig26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index 89cedaa1b..3cc044003 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -3479,22 +3479,20 @@ pub fn handleResponseMetadata(
this.redirect = url_buf;
} else {
var url_buf = URLBufferPool.get(default_allocator);
+ var fba = std.heap.FixedBufferAllocator.init(&url_buf.data);
const original_url = this.url;
- const port = original_url.getPortAuto();
-
- if (port == original_url.getDefaultPort()) {
- this.url = URL.parse(std.fmt.bufPrint(
- &url_buf.data,
- "{s}://{s}{s}",
- .{ original_url.displayProtocol(), original_url.displayHostname(), location },
- ) catch return error.RedirectURLTooLong);
- } else {
- this.url = URL.parse(std.fmt.bufPrint(
- &url_buf.data,
- "{s}://{s}:{d}{s}",
- .{ original_url.displayProtocol(), original_url.displayHostname(), port, location },
- ) catch return error.RedirectURLTooLong);
+
+ const new_url_ = bun.JSC.URL.join(
+ bun.String.fromUTF8(original_url.href),
+ bun.String.fromUTF8(location),
+ );
+ defer new_url_.deref();
+
+ if (new_url_.utf8ByteLength() > url_buf.data.len) {
+ return error.RedirectURLTooLong;
}
+ const new_url = new_url_.toUTF8(fba.allocator());
+ this.url = URL.parse(new_url.slice());
is_same_origin = strings.eqlCaseInsensitiveASCII(strings.withoutTrailingSlash(this.url.origin), strings.withoutTrailingSlash(original_url.origin), true);
deferred_redirect.* = this.redirect;