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:
Faheem Ahmad
2026-10-13 06:05:29 +09:00
committed by GitHub
co-authored by Cursor
parent d59ab6d977
commit af29247a78
10 changed files with 62 additions and 14 deletions
+2 -3
View File
@@ -4,6 +4,7 @@ import type {
CapturedWebScript,
ExportedWebScript,
} from "./webScriptExport.js";
import { urlDeclaresQueryOrFragment } from "./urlComponents.js";
const hash = (text: string): string =>
createHash("sha256").update(text).digest("hex");
@@ -94,9 +95,7 @@ const candidatePath = (script: CapturedWebScript): CandidatePath => {
return {
path: `origins/${hash(url.origin)}/${parts.join("/")}`,
reason:
// URL.search/hash collapse absent and explicitly empty components.
url.href.includes("?") ||
url.href.includes("#") ||
urlDeclaresQueryOrFragment(url) ||
url.username !== "" ||
url.password !== ""
? "URL query, fragment, or credentials cannot select a canonical local module."