fix: [#2088] Handle CSS hex escape sequences in querySelector#2134
Open
coffeeandwork wants to merge 1 commit intocapricorn86:masterfrom
Open
fix: [#2088] Handle CSS hex escape sequences in querySelector#2134coffeeandwork wants to merge 1 commit intocapricorn86:masterfrom
coffeeandwork wants to merge 1 commit intocapricorn86:masterfrom
Conversation
…tor selectors The selector parser was treating the trailing space in CSS hex escapes (e.g. \39 ) as a descendant combinator, causing selectors produced by CSS.escape() to throw or silently fail when IDs start with a digit. Fixed the group regexp to skip over escape sequences, updated the selector regexp so ID/class/attribute patterns can consume hex escapes, and switched ID/class/attribute name unescaping from a naive backslash strip to the existing cssUnescape() which properly decodes hex values.
Contributor
Author
|
The CI failure is in This is a known flaky test — #2013 tracks it and there are already PRs (#2014, #2116) trying to fix it. Unrelated to the selector parser changes here. All 157 querySelector tests passed. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
querySelector and querySelectorAll throw a SyntaxError (or silently return null) when the selector contains CSS hex escape sequences like
#\39 7e356d3-..., which is whatCSS.escape()produces for IDs starting with a digit.The root cause was in SelectorParser:
SELECTOR_GROUP_REGEXPwasn't escape-aware — it saw the trailing space in\39as a descendant combinator and split the selector in half.SELECTOR_REGEXP's ID/class/attribute patterns only handled single-character escapes (\.), not hex escapes (\39), so they couldn't consume the full escaped identifier./\\/g), which turned\39 7e...into397e...instead of decoding\39as the character9. ThecssUnescape()method that handles this correctly already existed — it just wasn't being used for these cases.Changes
SELECTOR_GROUP_REGEXPso hex/character escapes are consumed before their trailing space can be misread as a combinatorSELECTOR_REGEXPto match hex escapes (\\[0-9a-fA-F]{1,6}\s?) in ID, class, attribute name, and unquoted attribute value patternscssUnescape()ESCAPED_CHARACTER_REGEXPTesting
CSS.escape()with a UUID ID, hex escapes in ID selectors, and hex escapes in class selectorsFixes #2088