mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
5
src/js/thirdparty/node-fetch.ts
vendored
5
src/js/thirdparty/node-fetch.ts
vendored
@@ -126,7 +126,7 @@ var ResponsePrototype = Response.prototype;
|
||||
const kUrl = Symbol("kUrl");
|
||||
|
||||
class Request extends WebRequest {
|
||||
[kUrl]: string;
|
||||
[kUrl]?: string;
|
||||
|
||||
constructor(input, init) {
|
||||
// node-fetch is relaxed with the URL, for example, it allows "/" as a valid URL.
|
||||
@@ -137,12 +137,11 @@ class Request extends WebRequest {
|
||||
this[kUrl] = input;
|
||||
} else {
|
||||
super(input, init);
|
||||
this[kUrl] = input.url;
|
||||
}
|
||||
}
|
||||
|
||||
get url() {
|
||||
return this[kUrl];
|
||||
return this[kUrl] ?? super.url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
8
test/regression/issue/014865.test.ts
Normal file
8
test/regression/issue/014865.test.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { test, expect } from "bun:test";
|
||||
import { Request } from "node-fetch";
|
||||
|
||||
test("node fetch Request URL field is set even with a valid URL", () => {
|
||||
expect(new Request("/").url).toBe("/");
|
||||
expect(new Request("https://bun.sh/").url).toBe("https://bun.sh/");
|
||||
expect(new Request(new URL("https://bun.sh/")).url).toBe("https://bun.sh/");
|
||||
});
|
||||
Reference in New Issue
Block a user