Skip to content

HTML API: Allow raw text which cannot close its own element - #12914

Open
itzmekhokan wants to merge 4 commits into
WordPress:trunkfrom
itzmekhokan:feature/65824-allow-more-modifiable-text
Open

HTML API: Allow raw text which cannot close its own element#12914
itzmekhokan wants to merge 4 commits into
WordPress:trunkfrom
itzmekhokan:feature/65824-allow-more-modifiable-text

Conversation

@itzmekhokan

Copy link
Copy Markdown

WP_HTML_Tag_Processor::set_modifiable_text() rejects any content containing </ followed by the element's own tag name, even where that sequence cannot close the element. This relaxes the check to match the tokenizer.

What the problem was:

  • A plain stripos() substring test rejected safe text such as </xmp-tag> in an XMP element, or </scriptx> in a SCRIPT element with an unrecognized content type.

What the fix does:

  • Requires the tag name to be terminated by one of , \t, \f, \r, \n, /, or > before rejecting the update, at both cited sites.

Approach and why:

  • This is the check the tokenizer itself performs in the RAWTEXT / script-data end tag name states, so accepted text is exactly the text that round-trips. \f is retained even though WP's tokenizer does not currently treat it as a terminator, because browsers do.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Ticket analysis, tests and PR generates. All changes were reviewed and validated by me.


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.

@github-actions

github-actions Bot commented Aug 6, 2026

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 khokansardar, jonsurrell, shailu25.

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

@github-actions

github-actions Bot commented Aug 6, 2026

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.

@itzmekhokan
itzmekhokan force-pushed the feature/65824-allow-more-modifiable-text branch from e2fc957 to 0da1cf3 Compare August 6, 2026 14:13
* A tag name ends only at one of the characters matched below, so text
* such as `</xmp-tag>` cannot close the element and is safe to set.
*
* @see https://html.spec.whatwg.org/#rawtext-end-tag-name-state

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @see https://html.spec.whatwg.org/#rawtext-end-tag-name-state
* @link https://html.spec.whatwg.org/#rawtext-end-tag-name-state

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, applied in a58274f. I also switched the two @see spec URLs in the SCRIPT case above to @link so the patch is consistent.

* such as `</scriptx>` cannot change that structure and is safe to set.
*
* @see https://html.spec.whatwg.org/#script-data-end-tag-name-state
* @see https://html.spec.whatwg.org/#script-data-double-escape-start-state

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @see https://html.spec.whatwg.org/#script-data-double-escape-start-state
* @link https://html.spec.whatwg.org/#script-data-double-escape-start-state

* A tag name ends only at one of the characters matched below, so text
* such as `</scriptx>` cannot change that structure and is safe to set.
*
* @see https://html.spec.whatwg.org/#script-data-end-tag-name-state

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @see https://html.spec.whatwg.org/#script-data-end-tag-name-state
* @link https://html.spec.whatwg.org/#script-data-end-tag-name-state

`WP_HTML_Tag_Processor::set_modifiable_text()` rejected any content
containing `</` followed by the element's own tag name, even where
that sequence cannot close the element. A tag name only ends where
one of ` `, `\t`, `\f`, `\r`, `\n`, `/`, or `>` follows it, so text
such as `</xmp-tag>` inside an XMP element, or `</scriptx>` inside a
SCRIPT element with an unrecognized content type, is ordinary text
and round-trips safely.

Require that terminating character before rejecting the update.

Fixes #65824.
@itzmekhokan
itzmekhokan force-pushed the feature/65824-allow-more-modifiable-text branch from 0da1cf3 to a58274f Compare August 6, 2026 17:13

@sirreal sirreal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great, thank you. I left one bit of feedback, then I think this is ready (it will need to wait for WordPress 7.2).

Comment thread src/wp-includes/html-api/class-wp-html-tag-processor.php Outdated

@sirreal sirreal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

I think this is ready, pending CI.

If you want to add the adjacent fix, I'd be happy to accept it as well: #12914 (comment)

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