Skip to content

fix(parser): stop the lexers from hanging on a NUL character - #661

Merged
Brooooooklyn merged 3 commits into
voidzero-dev:mainfrom
GabeSilvaDev:fix/nul-ends-input
Oct 30, 2026
Merged

Brooooooklyn merged 3 commits into
voidzero-dev:mainfrom
GabeSilvaDev:fix/nul-ends-input

Conversation

@GabeSilvaDev

@GabeSilvaDev GabeSilvaDev commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

A NUL character in a template or a binding made the compiler loop forever.

Both lexers use '\0' as their end-of-input sentinel. In the HTML lexer the scanners stop at a NUL without moving, so the main loop (while index < length) never ends. In the expression lexer advance() refused to move past a character equal to EOF, so a host binding such as '[x]': 'a\0b' hung in the same way.

What Angular does

Angular's cursor peeks a NUL as $EOF (0), but advance() still moves past it (it only checks the offset). So a NUL stops only the loops that check peek() === $EOF:

A NUL stops here A NUL is read as text here
top-level loop, text comments, CDATA, DOCTYPE
interpolation (even inside a quote) raw text: <style>, <textarea>, <title>, <script>
tag and attribute names, unquoted values quoted attribute values (an interpolation inside still stops)
block parameters outside quotes block parameters inside quotes, [...] attribute names, ICU values

Changes

  • HTML lexer: the main loop and interpolations stop at a NUL. The scanners in the right column check the index instead of the character, so they read through it. ngc 22.2.2 gives the same results: <b>{{a}}</b>\0<i>{{b}}</i> keeps only <b>, <!--a\0b--><p>{{x}}</p> keeps the <p>, and <textarea>a\0b</textarea> keeps a\0b.
  • Interpolation: read the character after // before checking again, as Angular does. So {{ a //}}b is one interpolation, and {{ a //\0 }} is not cut at the NUL.
  • Expression lexer: advance() checks the index, not the character. Whitespace is skipped the same way in scanToken and inside ${...}: every character up to the space (NUL and the other control characters), plus NBSP. A NUL inside a string is still an unterminated string.

Checks

  • New lexer tests check the tokens and that there are no errors: text, interpolation, comments, CDATA, raw text, quoted attributes, block parameters, ICU, and ${a\0}. All of them fail on the first version of this PR, and the first two hang before it.
  • A harness compared our HTML tokens with Angular's tokenize() for 29 templates, with a NUL put at every position (743 cases). The only differences left also show up without a NUL (see below). The same check for the expression lexer found no NUL-only differences.
  • End to end against ngtsc 22.2.3, 26 of 28 NUL templates give the same output. The other 2 are older gaps that show up without a NUL too: @if drops expression errors, and there is no DOM schema check (NG8002).
  • The linker now links partial templates with a NUL inside an attribute value, comment or raw text (before, they were left unlinked).
  • cargo test --all-features (3760 tests), no-features (3618), conformance 1264/1264, napi vitest 401/401, and clippy on the changed lines all pass.

Not in this PR (also happen without a NUL)

  • An unterminated raw-text element (<style>a</stylex>) gets no error. Angular reports Unexpected character "EOF".
  • <!x> is an error for us, but a DOCTYPE token for Angular.
  • An unclosed ICU gets an error from our lexer. Angular's lexer reports none and leaves it to the parser.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 28, 2026 22:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-30T06:35:15.349311Z
We couldn’t complete this review. Comment @codex review to try again.
ecb0860 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Brooooooklyn and others added 2 commits October 30, 2026 13:51
Angular's cursor peeks a NUL as `$EOF`, but `advance()` still moves past it.
So only the loops that check `peek() === $EOF` stop there: the main loop,
text, interpolation, tag and attribute names, unquoted values, and block
parameters outside quotes. Comments, CDATA, DOCTYPE, raw text (`<style>`,
`<textarea>`, `<title>`, `<script>`), quoted attribute values, `[...]`
attribute names and ICU values read a NUL as text.

Cutting the input at the first NUL broke the second group. For example,
`<!--a\0b--><p>{{x}}</p>` gave an error, and `<textarea>a\0b</textarea>`
silently dropped the rest of the template, while ngtsc compiles both.

- HTML lexer: stop the main loop and interpolations at a NUL. The scanners
  that read to a closing marker now check the index, not the character.
- Interpolation: read the character after `//` before checking again, as
  Angular does (`{{ a //}}b` is one interpolation).
- Expression lexer: skip whitespace the same way in `${...}` as in
  `scanToken` (every character up to the space, and NBSP), so `${a\0}`
  compiles like it does in Angular.
- Tests: check the tokens and that there are no errors for each case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn
Brooooooklyn merged commit b14c575 into voidzero-dev:main Oct 30, 2026
9 checks passed
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.

3 participants