Skip to content

Commit

Permalink
fix(proxy): protect the program when querySelectorAll throws an excep…
Browse files Browse the repository at this point in the history
…tion (#547)

Co-authored-by: weifangchen <weifangchen@tencent.com>
  • Loading branch information
chenweifang4 and weifangchen authored May 17, 2023
1 parent ae71b02 commit a7f83fc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/wujie-core/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,19 @@ export function proxyGenerator(
}
if (propKey === "getElementsByClassName") arg = "." + arg;
if (propKey === "getElementsByName") arg = `[name="${arg}"]`;
return querySelectorAll.call(shadowRoot, arg);

// FIXME: This string must be a valid CSS selector string; if it's not, a SyntaxError exception is thrown;
// so we should ensure that the program can execute normally in case of exceptions.
// reference: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll

let res: NodeList[] | [];
try {
res = querySelectorAll.call(shadowRoot, arg);
} catch (error) {
res = [];
}

return res;
},
});
}
Expand Down

0 comments on commit a7f83fc

Please sign in to comment.