You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: avoid querySelector SyntaxError when option value contains special characters - #674
When the user moves the active option with the keyboard, RawOptionList scrolls the active cell of each column into view by looking up its li with querySelector('li[data-path-key="..."]'). The path key goes into a CSS attribute selector after escaping only the double quotes, so an option value with a backslash or a newline makes an invalid selector and the whole component throws:
SyntaxError: 'li[data-path-key="line1
line2"]' is not a valid selector
A value such as a Windows path (C:\) is a plausible case.
The effect now collects the li[data-path-key] elements once and finds the active one by comparing the data-path-key attribute to the key, so no selector has to be built from option values and no escaping is needed.
Test: should not crash when scrolling active option with backslash or newline in value opens a cascader with options C:\, a\"b and line1\nline2, moves the active option with ArrowDown and checks that each one becomes the active item and is scrolled into view. It fails on master with the SyntaxError above and passes now. npm test (12 suites, 129 passed, 2 skipped as before), npm run tsc and npm run lint (0 errors) pass.
This change stops keyboard navigation from crashing when option values contain backslashes, quotes, or newlines, and adds a regression test. No remaining merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: a2cccf42-eff7-4e14-bfb1-184077a1d053
Commits
Reviewing files that changed from the base of the PR and between 3d31b12 and 7ce5008.
Files selected for processing: 2
src/OptionList/List.tsx
tests/index.spec.tsx
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the user moves the active option with the keyboard,
RawOptionListscrolls the active cell of each column into view by looking up itsliwithquerySelector('li[data-path-key="..."]'). The path key goes into a CSS attribute selector after escaping only the double quotes, so an option value with a backslash or a newline makes an invalid selector and the whole component throws:A value such as a Windows path (
C:\) is a plausible case.The effect now collects the
li[data-path-key]elements once and finds the active one by comparing thedata-path-keyattribute to the key, so no selector has to be built from option values and no escaping is needed.Test:
should not crash when scrolling active option with backslash or newline in valueopens a cascader with optionsC:\,a\"bandline1\nline2, moves the active option with ArrowDown and checks that each one becomes the active item and is scrolled into view. It fails onmasterwith theSyntaxErrorabove and passes now.npm test(12 suites, 129 passed, 2 skipped as before),npm run tscandnpm run lint(0 errors) pass.Summary by CodeRabbit