mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
handle invalid URL in Location header for fetch() (#9305)
This commit is contained in:
@@ -1228,6 +1228,7 @@ pub const Fetch = struct {
|
||||
error.FailedToOpenSocket => bun.String.static("Was there a typo in the url or port?"),
|
||||
error.TooManyRedirects => bun.String.static("The response redirected too many times. For more information, pass `verbose: true` in the second argument to fetch()"),
|
||||
error.ConnectionRefused => bun.String.static("Unable to connect. Is the computer able to access the url?"),
|
||||
error.RedirectURLInvalid => bun.String.static("Redirect URL in Location header is invalid."),
|
||||
|
||||
error.UNABLE_TO_GET_ISSUER_CERT => bun.String.static("unable to get issuer certificate"),
|
||||
error.UNABLE_TO_GET_CRL => bun.String.static("unable to get certificate CRL"),
|
||||
|
||||
@@ -3568,6 +3568,10 @@ pub fn handleResponseMetadata(
|
||||
|
||||
const normalized_url = JSC.URL.hrefFromString(bun.String.fromBytes(string_builder.allocatedSlice()));
|
||||
defer normalized_url.deref();
|
||||
if (normalized_url.tag == .Dead) {
|
||||
// URL__getHref failed, dont pass dead tagged string to toOwnedSlice.
|
||||
return error.RedirectURLInvalid;
|
||||
}
|
||||
const normalized_url_str = try normalized_url.toOwnedSlice(bun.default_allocator);
|
||||
|
||||
const new_url = URL.parse(normalized_url_str);
|
||||
|
||||
@@ -772,7 +772,7 @@ pub inline fn err(error_name: anytype, comptime fmt: []const u8, args: anytype)
|
||||
}
|
||||
|
||||
// TODO: convert zig errors to errno for better searchability?
|
||||
if (errors.len == 1) break :display_name .{ comptime @errorName(errors[0]), true };
|
||||
if (errors.len == 1) break :display_name .{ errors[0].name, true };
|
||||
}
|
||||
|
||||
break :display_name .{ @errorName(error_name), false };
|
||||
|
||||
Reference in New Issue
Block a user