fix(javascript): never read window or document open as XHR
`window.open(url, "/preview")` has a computed first argument and a path-shaped browsing-context name, so the computed-method XHR fallback reported the target name as an endpoint. Browsing-context and document `open` calls never take an XHR method and request URL; skip them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
602d0021d4
commit
ae849a7281
@@ -383,6 +383,13 @@ const xhrOpenUrl = (
|
||||
: undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Browsing-context and document `open` take a URL or type first and a target
|
||||
* name second, never an XHR method and request URL.
|
||||
*/
|
||||
const WINDOW_OPEN_CALL =
|
||||
/(?:^|\.)(?:window|self|globalThis|top|parent|opener|frames|document)\.open$/u;
|
||||
|
||||
/** Select the literal URL argument for recognized network callees. */
|
||||
export const endpointArgument = (
|
||||
name: string,
|
||||
@@ -395,7 +402,8 @@ export const endpointArgument = (
|
||||
): string | undefined => {
|
||||
if (name === "fetch" || name.endsWith(".fetch") || name === "WebSocket")
|
||||
return stringValue(args[0]);
|
||||
if (name.endsWith(".open")) return xhrOpenUrl(args[0], args[1]);
|
||||
if (name.endsWith(".open") && !WINDOW_OPEN_CALL.test(name))
|
||||
return xhrOpenUrl(args[0], args[1]);
|
||||
if (
|
||||
["get", "post", "put", "patch", "delete", "request"].some(
|
||||
(method) => name === method || name.endsWith(`.${method}`),
|
||||
|
||||
@@ -185,6 +185,9 @@ describe("web bundle static-analysis parity", () => {
|
||||
xhr.open(method, "/dynamic-method");
|
||||
fs.open(path, "r", done);
|
||||
window.open(url, "_blank");
|
||||
window.open(url, "/preview");
|
||||
globalThis.open(url, "./frame");
|
||||
document.open("text/html", "/replace");
|
||||
`),
|
||||
);
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user