Skip to content

Blocks: Stop reporting a delimiter for trailing partial comments - #13604

Open
sirreal wants to merge 2 commits into
WordPress:trunkfrom
sirreal:fix/block-processor-trailing-partial-comment
Open

sirreal wants to merge 2 commits into
WordPress:trunkfrom
sirreal:fix/block-processor-trailing-partial-comment

Conversation

@sirreal

@sirreal sirreal commented Sep 18, 2026

Copy link
Copy Markdown
Member

Stop WP_Block_Processor from reporting an extra block delimiter when HTML content ends in <, <!, or <!-.

For example, <!-- wp:a -->text< makes next_delimiter() report core/a twice. With no previous delimiter, text< reports a delimiter with an empty block name.

The processor returns the final HTML span but then treats the trailing bytes as a delimiter, reusing the previous delimiter's state. Set INCOMPLETE_INPUT when returning that span so the next call stops parsing. The example then produces one core/a delimiter and an HTML span; next_token() returns false on the following call.

Ten test cases cover the three partial comment prefixes, preceding opening, void and closing delimiters, and two complete-input controls. Eight cases fail before the fix. Local validation passed: 232 block-processor tests and 633 blocks tests.

Trac ticket: https://core.trac.wordpress.org/ticket/66138

Use of AI Tools

AI assistance: Yes
Tools: Claude Code, Codex
Models: Claude Opus, GPT-6
Used for: Finding the defect, drafting the fix and tests, and editing this description.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Comment thread src/wp-includes/class-wp-block-processor.php Outdated
Comment thread tests/phpunit/tests/block-processor/wpBlockProcessor.php Outdated
@sirreal
sirreal requested a review from dmsnell September 18, 2026 11:24
@sirreal
sirreal marked this pull request as ready for review September 18, 2026 11:24
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

When a document ends in `<`, `<!`, or `<!-` and no further `<!--` follows,
`WP_Block_Processor::next_token()` reports a block delimiter which is not in
the document. `next_delimiter()` returns true for it, `opens_block()` is true,
and the reported name, attributes, and delimiter type repeat the previous
delimiter, or the uninitialized defaults when there was no previous delimiter.
The open-block stack also gains an entry which is never popped.

The branch which handles a missing `<!--` emits the preceding HTML span with
`matched_delimiter_at` set before the end of the document, because the trailing
partial is measured into the span's length. The re-entry at the top of
`next_token()` only completes when `matched_delimiter_at` reaches the end, so
it promotes the HTML span to a matched delimiter instead.

Record the incomplete input when the span is emitted. The guard at the top of
`next_token()` then stops the promotion, and the existing reporting of
`INCOMPLETE_INPUT` is preserved.
@sirreal
sirreal force-pushed the fix/block-processor-trailing-partial-comment branch from a58d436 to cdd5542 Compare September 18, 2026 11:28
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.

1 participant