stringify escapes leading digits in pseudo-class arguments (:nth-child(1) becomes :nth-child(\31 ))
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 83/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend-api-design
Research direction
The issue points to src/stringify.ts, where pseudo-class data is passed through escapeName. Read that call and the leading-digit escape logic added in #1802 to see how they interact. Reproduce the listed cases with the parse and stringify example; done means pseudo-class arguments round-trip unchanged while identifier escaping remains scoped to identifiers.
Written by the indexing model from the issue text.
Description
Since #1802 (b8420ca, not released yet), stringify applies the identifier escaping for a leading digit to pseudo-class arguments as well, so :nth-child() and similar selectors no longer round-trip and become invalid.
import { parse, stringify } from "css-what";
for (const s of [
":nth-child(1)",
":nth-child(2n+1)",
":nth-child(-2n-1)",
":nth-of-type(3)",
":nth-child(2 of .a)",
":contains(1)",
]) {
console.log(s, "->", stringify(parse(s)));
}
On main (3618701):
:nth-child(1) -> :nth-child(\31 )
:nth-child(2n+1) -> :nth-child(\32 n+1)
:nth-child(-2n-1) -> :nth-child(-\32 n-1)
:nth-of-type(3) -> :nth-of-type(\33 )
:nth-child(2 of .a) -> :nth-child(\32 of .a)
:contains(1) -> :contains(\31 )
8.0.0 prints every selector unchanged, which is the expected output. document.querySelectorAll(":nth-child(\\31 )") throws a SyntaxError in Chromium, since An+B is not an identifier (css-syntax-3 §6).
In src/stringify.ts, pseudo-class data goes through escapeName(token.data, charsToEscapeInPseudoValue), and the leading-digit / leading -digit / lone - escapes added in #1802 run for that call too. They should only apply to identifiers.
Credit: https://ucsbplse.github.io/
- Dominant language
- TypeScript
- Stars
- 249
- Forks
- 50
- Avg merge
- 1h 50m
- Merged PRs (30d)
- 16
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from fb55/css-what
-
[Feature request] Support for forgiving selector parsingPossibly taken @Boulea7 claimed this 34 days ago. Opengood-first-issue
Difficulty 3/5 1-2 days Newbie friendliness 45/100
fb55/css-what#1254 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
ranxianglei/billion-context#5893 ·
Maintainers usually reply within 1 day
-
enhancement security severity:low
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Battle-Cattle/BCUK-Bot-4#959 ·
Maintainers usually reply within 1 day
-
[Bug]: Claude account rows no longer show the email (since #8055), so "Account 1, 2, 3" cannot be told apartPossibly taken A pull request linked to this issue is open or already merged. Openaccount-pool bug gui
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
lidge-jun/opencodex#8286 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day