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:
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user