Accept whitespace around the offset sign in :nth-child(An+B) - #192
Merged
TylerBrinks merged 1 commit intoJul 23, 2026
Merged
Conversation
jhaygood86
marked this pull request as ready for review
July 22, 2026 21:19
jhaygood86
marked this pull request as draft
July 22, 2026 21:40
jhaygood86
marked this pull request as ready for review
July 22, 2026 21:43
<a-n-plus-b> includes the production <n-dimension> ['+' | '-'] <signless-integer> and "whitespace is permitted on either side of the + or - that separates the An and B parts when both are present", with "3n + 1" given as a valid example (CSS Syntax 3 6.1, 6.2). The two spellings lex differently: "10n+1" yields a single signed <number>, while "10n + 1" yields a standalone '+' delim followed by a signless integer. ChildFunctionState.OnOffset handled only whitespace and numbers, so the standalone sign fell through to OnBeforeOf, which is looking for "of" or ')', and marked the selector invalid. The rule was then dropped. Handle the delim in OnOffset and add an AfterOffsetSign state for the digits that follow. That state requires a <signless-integer> - "a <number-token> with its type flag set to integer, and no sign character" - so "3n + -6", listed as an invalid example in 6.1, stays invalid, as do "10n + +1" and a repeated sign.
jhaygood86
force-pushed
the
bugfix/an-b-selector-spaced-sign
branch
from
July 22, 2026 21:49
406c52b to
6468c3f
Compare
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.
Problem
CSS Syntax 3 §6.2 defines
<a-n-plus-b>with, among others, the production:and §6.1 states:
listing
3n + 1,+3n - 2and-n+ 6as valid examples.The two spellings lex differently:
10n10n+1<number>+110n + 1<whitespace>,<delim +>,<whitespace>,<number>1ChildFunctionState.OnOffsethandles onlyWhitespaceandNumber, so the standalone delim falls through itsdefault:arm intoOnBeforeOf— which is looking forofor)— and sets_valid = false, dropping the rule.This affects
:nth-child(),:nth-last-child(),:nth-of-type()and:nth-last-of-type()alike.Fix
Handle the
+/-delim inOnOffsetand add anAfterOffsetSignstate for the digits that follow.That state is deliberately strict rather than just setting a sign flag and staying put, because the production calls for a
<signless-integer>, which §6.2 defines as:So a second sign stays invalid — and §6.1 lists
3n + -6among its invalid examples, which is exactly this case.NumberToken.Datapreserves the authored sign character, which is what the check keys on.Tests
20 theory cases in
SelectorsTests.cs, assertingChildSelector.Step/Offsetrather than round-tripped text:10n + 1,10n - 1,2n + 0,-2n + 3, and extra internal whitespaceodd/even, which must keep working unchanged:nth-*variants3n + -6,3 n,+ 2n,+ 2— plus10n + +1,10n + + 1and10n + n8 fail on
master; the invalid cases pass both before and after, confirming the fix doesn't loosen the grammar. The full suite (1263 existing tests) stays green with no existing assertion modified, and all seven target frameworks build with no new warnings.