Compare commits

...

5 Commits

Author SHA1 Message Date
RiskyMH
7c5db11ead add test 2025-05-14 12:00:33 +10:00
RiskyMH
2970c85d2c Merge remote-tracking branch 'origin/main' into kai/fix-preconnect-port 2025-05-14 11:54:13 +10:00
Kai Tamkun
2bc637ccff Move emptiness check to hasValidPort 2025-01-31 18:55:29 -08:00
Kai Tamkun
2e9e448498 Do validate the port, but slightly more cleverly 2025-01-31 18:40:38 -08:00
Kai Tamkun
3ee9af7649 Fix default ports being rejected in preconnect 2025-01-31 18:31:56 -08:00
2 changed files with 8 additions and 1 deletions

View File

@@ -154,7 +154,7 @@ pub const URL = struct {
}
pub fn hasValidPort(this: *const URL) bool {
return (this.getPort() orelse 0) > 0;
return this.port.len == 0 or (this.getPort() orelse 0) > 0;
}
pub fn isEmpty(this: *const URL) bool {

View File

@@ -29,6 +29,12 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
expect(response.status).toBe(200);
});
it("fetch.preconnect works without specifying a port", async () => {
fetch.preconnect("http://example.com");
const response = await fetch("http://example.com");
expect(response.status).toBe(200);
});
describe("doesn't break the request when", () => {
for (let endOrTerminate of ["end", "terminate", "shutdown"]) {
describe(endOrTerminate, () => {
@@ -109,6 +115,7 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
it("fetch.preconnect validates the URL", async () => {
expect(() => fetch.preconnect("http://localhost:0")).toThrow();
expect(() => fetch.preconnect("http://localhost")).not.toThrow();
expect(() => fetch.preconnect("")).toThrow();
expect(() => fetch.preconnect(" ")).toThrow();
expect(() => fetch.preconnect("unix:///tmp/foo")).toThrow();