Skip to content

fix(parser): end processing instructions at a NUL like Angular - #755

Merged
Brooooooklyn merged 2 commits into
voidzero-dev:mainfrom
eintim:fix/processing-instructions-simple
Dec 4, 2026
Merged

Brooooooklyn merged 2 commits into
voidzero-dev:mainfrom
eintim:fix/processing-instructions-simple

Conversation

@eintim

@eintim eintim commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

#756 added processing instruction support to the HTML lexer. One case still differs from Angular: a NUL inside the instruction.

Angular's cursor peeks a NUL as EOF but moves past it, so _attemptUntilIgnoreQuotes stops at the NUL and the instruction ends there. We kept scanning to the ?>.

Template Angular 22.3.0 Before
<?x\0y?>z instruction x, text y?>z instruction x\0y, text z
<?x\\0y?>z in an escaped string (\0, \000, \x00, \u0000, \u{0}) instruction x, text y?>z instruction x, and y?>z is lost
<?x\ in an escaped string (lone trailing backslash) Unexpected character "EOF" same (kept by this PR)

Changes

  • scan_processing_instruction also stops at a NUL: a raw NUL, or, in an escaped string, an escaped NUL (which peek reads as U+FFFD). code_point_escape_value_at gives the escape's code point for that check. A backslash that ends an escaped string also peeks as EOF, but it is not a NUL, so the EOF error stays.
  • Ports upstream's processing instruction lexer tests (all 6 in describe("processing instructions")) and the parser's should ignore processing instruction.
  • Adds lexer cases checked against Angular 22.3.0: all quote kinds and an escaped quote, the error offsets for an unterminated instruction and for ? without >, <? ending text and interpolations, and the NUL cases with spans (NUL at the end, NUL inside quotes, backslash before a NUL, trailing backslash).

Known differences left for later

A fuzz run (23k inputs vs Angular 22.3.0) shows this PR fixes 3272 mismatches and adds none of its own. These older differences remain; they come from shared escape and line-continuation code, not from the processing instruction scan:

  • An escaped NUL inside quotes (<?"\0"?>z) still loses the text after the instruction (the escaped-string pass cuts the tokens at any NUL; Angular keeps going).
  • An instruction that ends at a NUL followed by a bad escape (<?x\0\u{y): Angular drops the instruction, we keep it.
  • A line continuation (\ + newline) before a quote or a NUL is read differently from Angular.
  • After ?, an escaped NUL is reported as Unexpected character "�" instead of "EOF".

@eintim
eintim force-pushed the fix/processing-instructions-simple branch from c48b4d8 to a64b1ea Compare December 4, 2026 06:23
@eintim eintim changed the title fix(parser): skip processing instructions like Angular fix(parser): end processing instructions at a NUL like Angular Dec 4, 2026
@eintim
eintim force-pushed the fix/processing-instructions-simple branch from a64b1ea to 1339676 Compare December 4, 2026 06:36
Angular's cursor peeks a NUL as EOF, so `_attemptUntilIgnoreQuotes` stops
there and the instruction ends at the NUL: `<?x\0y?>z` is the instruction
`x` and then the text `y?>z`. We kept scanning to the `?>`. In an escaped
string an escaped NUL (`\0`, `\x00`, `\u0000`, `\u{0}`) does the same; we
also lost the text after it there.

Also port upstream's processing instruction lexer and parser tests, with
extra cases checked against Angular 22.3.0.
@eintim
eintim force-pushed the fix/processing-instructions-simple branch from 1339676 to 2928bb4 Compare December 4, 2026 06:44
…ing instruction

In an escaped string a lone backslash at the end peeks as NUL, so the
instruction scan stopped there and `<?x\` became the instruction `x` with
no error. Angular moves past the backslash to the end of the input and
reports `Unexpected character "EOF"`. `at_nul` is now false there and at
the end of the input.

Also port the upstream `should store the location of a processing
instruction` test, give the ported tests their upstream names with only
the upstream cases, move our extra cases into their own tests, check
spans in the NUL tests, and move the escape-length docs to
`code_point_escape_value_at`.

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

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T07:49:50.715795Z f043ec7 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: f043ec7b84

ℹ️ 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 883830f into voidzero-dev:main Dec 4, 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.

2 participants