Repository navigation
[lexical-html] Bug Fix: reject an empty selector group in parseSelector - #9083
Merged
Merged
Conversation
A comma separated group with no tag and no refinement is the shape a lone `*` produces, and the parser could not tell that apart from a group that is simply empty. So `h1,,h2`, `h1,`, `,h1`, `""` and a whitespace only source all compiled into a selector that matches every element, and an import rule written that way captured the whole document instead of the handful of elements the author meant. parseSimpleSelector now reports whether it consumed a `*`, and parseSelector asserts each group has a tag, a refinement, or that star, using the position annotated Cursor.assert the file already uses for input outside its subset.
luantaraschi
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 20, 2026 00:53
etrepum
reviewed
Aug 20, 2026
| } | ||
|
|
||
| return {predicates, tags}; | ||
| return {isUniversal, predicates, tags}; |
Collaborator
There was a problem hiding this comment.
I don't think the representation should change to support this, you should simply throw in the parser here when this condition is detected
Contributor
Author
There was a problem hiding this comment.
Makes sense, done. The check moved into parseSimpleSelector and the extra field is gone, so ParsedSimpleSelector is back to what it was. Same message and column as before, so the test did not change.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Aug 20, 2026
Merged
This branch was successfully deployed
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.
Description
parseSelectorbuilds oneParsedSimpleSelectorper comma separated group, and a group with no tag and no refinement is treated as a wildcard. That is right for*, which is exactly that shape, but the parser cannot tell*from a group that is simply empty, so a hole in a selector list, a stray comma, or an empty string all come back as a selector that matches every element.Measured through
getSelectorImpl, onmain, asking whether the compiled selector matches a<div>:<div>h1,,h2h1,,h1h1, ,h2""" "h1parseSelectoris exported from@lexical/htmland is whatsel.css()calls, so an import rule written with any of those sources quietly captures every element instead of the handful the author meant, and the rule that should have won is shadowed. The file already says what it wants to do with input outside its subset:and it has the position annotated
Cursor.assertfor exactly that. The empty group was the one case that slipped through, and the old code says so in a comment on an emptyif.So
parseSimpleSelectornow reports whether it consumed a*, andparseSelectorasserts that every group has a tag, a refinement, or that star. Nothing else changes:*,h1, *and*.foostill parse, and the tag dispatch and the OR predicate for lists are untouched.Test plan
Before
CSS parser rejects an empty selector or a hole in a selector listfails onmain: none of the six malformed sources throws.After
That test passes, and the rest of the file is unaffected.
Full
npx vitest runfor the repo is green as well, with the same result as on a clean checkout here.