Skip to content

tokenizer: Fix ident start check for a hyphen before an invalid escape. - #466

Closed
NoobInTheNet wants to merge 1 commit into
servo:mainfrom
NoobInTheNet:tokenizer-hyphen-invalid-escape
Closed

NoobInTheNet wants to merge 1 commit into
servo:mainfrom
NoobInTheNet:tokenizer-hyphen-invalid-escape

Conversation

@NoobInTheNet

Copy link
Copy Markdown

Fixes #440.

In the - arm of is_ident_start, the check for an invalid escape looked for the newline at offset 1. That byte is the backslash itself, so the check never fired and -\<newline> started an identifier. The newline is at offset 2.

Per CSS Syntax §4.3.9, - followed by \ starts an ident sequence only if the backslash begins a valid escape. A backslash before a newline does not.

Hash, at-keyword and dimension tokens use the same check, so the test covers -\, @-\, #-\ and 1-\ before a newline. css-tokenizer-tests has the first one as tests/ident/0004.

Note

AI disclosure: this bug turned up while I was moving the CSS scan of rustywind to cssparser in avencera/rustywind#168. I did that work with Claude Code and its model Claude Fable 5.2. The tool wrote this patch and drafted this description. I have read the change, run the tests, and can explain it. I know the AI Usage Policy says no as written, so close this if you prefer. Someone else can then write the fix.

For `-\`, is_ident_start looked for the newline at offset 1, which is the
backslash itself, so `-\<newline>` started an identifier. The newline is
at offset 2.

Fixes servo#440

Assisted-by: Claude Code (claude-fable-5-2)
@mrobinson mrobinson closed this Nov 25, 2026
@NoobInTheNet

Copy link
Copy Markdown
Author

@mrobinson, you closed this without a word. If the reason is the AI Usage Policy, please say so. One line from you would have cost less than this fix cost me.

The PR is a one-line fix in src/tokenizer.rs (has_newline_at(1) to has_newline_at(2)) plus an 18-line test, +20 −1 in the diff, with a 650-character write-up. Without the fix the test fails with Ident("-") instead of Delim('-'). With it, the full suite passes, 62 of 62. WebKit's CSSTokenizer::nextCharsAreIdentifier checks the character after the backslash the same way, and css-tokenizer-tests expects this result in tests/ident/0004. The bug dates from 8aafbd2, on December 23, 2014.

A reviewer can check it all in two minutes, and it would have counted as good practice long before LLMs existed. What do you expect, that I retype a 19-line diff by hand and write the same 650 characters again?

I'm all for the social responsibility behind your policy. I know Igalia has 25 years behind it, a lot of them on embedded browsers like WPE WebKit. I get the old-school instinct that comes with that, up to a point. I also see why open-source projects are wary of AI PRs: they're usually messy and sloppy, and they burn reviewer time. This PR is none of that, though, and the policy treats it the same.

I've written code for over 12 years, most of it by hand, well before coding assistants existed. An LLM made it quick to trace a tokenizer bug from 2014 and turn it into a tested patch. That bug has sat for almost 12 years in the most downloaded CSS parser on crates.io, which has about 130 million downloads. Accessibility isn't only physical, and our field is full of unique profiles and non-linear thinkers. For me, an LLM puts structure on my thoughts and helps me carry them through. It also makes the result easier for reviewers like you to follow. The only thing a blanket ban achieves here is that people lose the will to contribute.

Your TSC keeps coming back to this. In early 2025 it reviewed a Copilot trial that had produced WritableStream (servo/servo#34844, about 2,900 lines). The vote was a tie. In April 2025 it proposed allowing AI tools "to make the project more inclusive and accessible" (servo/servo#36379), then dropped that after public feedback. In September 2026 it talked about security reports made with LLMs. A TSC member said a flaky-test case "makes me question our LLM policy." On November 18 the policy gained an exception for minimized test cases made with AI tools (servo/book#289). The accessibility part hasn't come back since April 2025, so I'm asking for it at the TSC meeting on November 30 (servo/project#256).

@SimonSapin @emilio, you made the policy explicit for this crate in #465. On #464, Emilio wrote: "I'd personally be ok with AI-generated code as long as the author is accountable for it / understands it (and defends it as needed with human words)." I'm that author, and I'll answer any question about this change myself. I'd like it reopened for review.

Thanks for reading all of it. I know parts sound hard, and I apologize in advance if they hurt anyone, because that was never my aim. If you still think rejecting these contributions is the right path, it's your call. In that case I'll put my effort into Rust CSS parsers that accept disclosed AI help, such as swc's swc_css_parser or Biome's CSS parser.

With much love, from the southeast coast of Spain (Alicante) to the northwest one (Galicia) 👋😉.

Note

And yes, I drafted this comment with an LLM again. I find structuring my thoughts challenging with ADHD. By hand, this would take much more time and effort. The message would likely end up even more confusing, too. The points are mine, and so is the decision to post it.

@jdm

jdm commented Nov 25, 2026

Copy link
Copy Markdown
Member

I know the AI Usage Policy says no as written, so close this if you prefer. Someone else can then write the fix.

I don't think there's anything to discuss here. You know what the policy is and you invited us to close the PR, and we did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

is_ident_start reads the wrong byte for a hyphen before a backslash

3 participants