fix: honor empty URL query and fragment markers (#2091)
URL.search and URL.hash are empty for both a missing component and an explicit empty one, so endpoint and origin checks were accepting URLs the callers meant to reject. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { urlDeclaresQueryOrFragment } from "./urlComponents.js";
|
||||
|
||||
describe("URL query and fragment spelling", () => {
|
||||
it("treats an explicit empty query or fragment as present", () => {
|
||||
expect(urlDeclaresQueryOrFragment(new URL("https://a.test/main.js"))).toBe(
|
||||
false,
|
||||
);
|
||||
expect(
|
||||
urlDeclaresQueryOrFragment(new URL("https://a.test/%3Ffile.js")),
|
||||
).toBe(false);
|
||||
for (const value of [
|
||||
"https://a.test/main.js?",
|
||||
"https://a.test/main.js#",
|
||||
"https://a.test/main.js?#",
|
||||
"https://a.test/main.js?v=1",
|
||||
"https://a.test/main.js#part",
|
||||
])
|
||||
expect(urlDeclaresQueryOrFragment(new URL(value)), value).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user