This commit is contained in:
pfg
2024-11-02 17:13:31 -07:00
committed by GitHub
parent 5e5e7c60f1
commit 497fa59bf0
2 changed files with 10 additions and 3 deletions

View File

@@ -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;
}
}

View 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/");
});