Fix case-sensitive matching of and/or and from/to keywords in CSS parsers - #240
Draft
meziantou wants to merge 2 commits into
Draft
Fix case-sensitive matching of and/or and from/to keywords in CSS parsers#240meziantou wants to merge 2 commits into
meziantou wants to merge 2 commits into
Conversation
The @supports condition parser compared the "and" / "or" keywords with ordinal equality, so an uppercase or mixed-case keyword silently discarded the whole conditional group and every rule inside it. The keyframe selector parser did the same for "from" / "to", leaving the rule in the CSSOM with a null key. Switched both to the case-insensitive Isi helper, including the chain continuation in Scan, which compared each subsequent keyword against the raw text of the first one.
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.
Types of Changes
Prerequisites
Please make sure you can check the following two boxes:
Contribution Type
What types of changes does your code introduce? Put an
xin all the boxes that apply:Description
CSS keywords are ASCII case-insensitive, but two micro parsers compared them with ordinal equality.
ConditionParserused.Is(...)for theand/orkeywords in@supportsconditions.Negationon the line just above already used the case-insensitive.Isi(...)fornot, which is what makes the divergence visible:@supports NOT (...)worked, while@supports (color: red) AND (display: flex) { ... }parsed to zero rules, silently discarding the conditional group and every rule inside it with no parse error.A third comparison in
Scanhad the same problem. It compares each subsequent keyword against the raw text of the first one, so a chain like(a) And (b) aND (c)still truncated after the second group even once the first two comparisons were fixed.KeyframeParserused.Is(...)forfrom/to.@keyframes x { FROM {...} TO {...} }failed selector parsing, leavingCssKeyframeRule._selectornull. The rule stays in the CSSOM with a nullKeyText, so the animation endpoints vanish and the round-tripped CSS is invalid.Changes
Switched all five comparisons to the case-insensitive
Isihelper:Parser/Micro/ConditionParser.cs—and/orinConjunctionOrDisjunction, and the chain continuation inScanParser/Micro/KeyframeParser.cs—from/toTests
7 new tests, each confirmed failing before the change and passing after:
Rules/CssSupports.cs— uppercaseAND, uppercaseOR, a mixed-caseAnd/aNDchain, and one asserting the inner rules of an uppercase-ANDgroup surviveRules/CssKeyframeRule.cs—FROM,TO, and mixed-caseFrom, ToFull suite: 2094 passed, 0 failed.
Notes for reviewers
Parser/confirms the only remaining ordinal.Is(issheet.Href.Is(href)inCssParser.cs, a URL comparison that should stay case-sensitive.