Repository navigation
fix: look up menu items by data-menu-id attribute without unescaped selector interpolation - #907
mokshupadhyay wants to merge 1 commit into
Conversation
…elector interpolation
|
@mokshupadhyay is attempting to deploy a commit to the afc163's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. Walkthrough
Changes菜单元素查找
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Low Suggested reviewers: Merge Risk:
|
The keyboard navigation of
Menu(refreshElementsinsrc/hooks/useAccessibility.ts) finds the DOM node of each item withdocument.querySelector("[data-menu-id='<id>']"), with the item key written into the selector as it is. A key that contains an apostrophe, a backslash or a newline makes an invalid selector, and the arrow keys then throw:An item key such as
Women's(or one that comes from user data) is enough. It is the same class of bug as react-component/cascader#674 and react-component/tabs#1031.refreshElementsnow collects the[data-menu-id]nodes once into aMap(the first node wins, asquerySelectorreturned the first match in document order) and looks each key up bygetMenuId(id, key), so no selector is built from keys. It also scans the document once instead of once per key.Test:
navigates items whose keys contain quotes, backslashes, or newlinesintests/Keyboard.spec.tsxfails onmasterwith theSyntaxErrorabove and passes now.npm test(15 suites, 159 tests),npm run tsc,npm run lint(0 errors) and prettier on the changed files pass.Summary by CodeRabbit