Repository navigation
RichText: close non-void inline object elements - #85895
salvatorecorsi wants to merge 6 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
|
The updated head Earlier CI follow-upUpdate for Earlier CI follow-up (previous head)Could a maintainer rerun the failed jobs in this E2E run? The autocomplete test failed during REST user setup/cleanup, and report merging hit a corrupt archive. The WebKit writing-flow test also failed its selection/toolbar assertions; I haven't established whether that is intermittent or related to this patch. My targeted rerun attempt was refused, so I haven't retried it. |
dmsnell
left a comment
There was a problem hiding this comment.
Looks good. It makes me wonder why we’re creating the HTML via string interpolation, and rather wonder if we would do well to rely on createElement() and createElementNS() and createComment() and the like.
it’s worth pointing out that the DOM methods and this code supports the creation of broken HTML comments, and that’s something we should check for and reject.
in fact, it looks like escape-html could use a lot of work. I’d be happy to help review and guide that.
| 'frame', | ||
| 'keygen', | ||
| 'param', | ||
| ] ); |
There was a problem hiding this comment.
this list matches the HTML API’s copy, lifted from the spec.
it would be worth linking to where these are defined.
/**
* @link https://html.spec.whatwg.org/#void-elements
* @link https://html.spec.whatwg.org/#serialising-html-fragments
*/| } | ||
|
|
||
| if ( object ) { | ||
| if ( object && type && VOID_ELEMENTS.has( type.toLowerCase() ) ) { |
There was a problem hiding this comment.
is type guaranteed to be upper-case for tag names? if so, we could define the Set() with upper-case variants and skip the string conversion
What?
Close non-void RichText inline objects when converting them to HTML, and preserve their stored children.
Closes #85890.
Why?
A plugin can register a
spanas an inline object, buttoHTMLString()currently emits only its opening tag. Text following the object then becomes part of that element when the HTML is parsed. A non-editable object also loses its stored inner HTML through the same early return.How?
Use a private, case-insensitive lookup to keep only void object elements open-ended. Non-void objects use the existing children-and-closing-tag path. The lookup retains the obsolete void elements browsers still handle for compatibility. The check stays restricted to objects, so an existing non-object format registered with a void tag name keeps its selected text.
Testing Instructions
In a WordPress editor page with
wp.richTextloaded, run:The result should be
before <span class="inline-token"></span>after. Reparse it and confirm thatafteris outside the span. Repeat with a non-editable span containing<em>Token</em>: both the inner HTML and the following text should survive. Image and line-break objects should still serialize without closing tags.The regression tests use real format registration, insertion and parsing. The initial regression set fails its five non-void cases on the exact unfixed source and passes ten compatibility controls. An additional case verifies that an empty object with a registered
data-idretains its replacement character and mapped attributes after parsing. The fixed implementation passes the complete rich-text package tests (244 tests) and related raw-handling/serialization checks (459 tests, including all 377 existing block fixtures).The full production build, rich-text development typecheck, scoped lint and test conventions passed. The built package's public APIs were also checked in WordPress with Chromium DOM reparsing. The existing parser behavior that ignores an empty class-only span remains unchanged; attributed and non-editable objects retain their data. The routing check retains the known Windows path-separator discovery failure. These checks do not cover the full editor save flow or Docker E2E.
Hosted E2E is not green: one WebKit shard failed during autocomplete REST fixture cleanup/setup and writing-flow selection assertions, and report merging failed while reading an archive. A targeted rerun was refused and has been requested once from a maintainer; the writing-flow failure has not been established as either intermittent or caused by this patch. The missing type-label checks are a separate maintainer-only requirement.
Validation after trunk update (2026-11-02)
Merged trunk
c6b054ddff32e160158b538f62d40963c80f5743normally and validated headefd4f047d8e2f5e2b0202506875aea7298262b29.Current trunk merged without conflicts and the original serializer and regression test blobs remained identical.
The required type label still needs maintainer action.
Validation update — 9 November 2026
Merged trunk
afa2c6a9baec79a4fdfb40ca59adaae410cc5feband validated published head46cb0395927fdddd2bf0e94fb90527be5ba694c6. This includes the required trunk baseline.These are local validation results; hosted CI and maintainer-only label requirements remain separate.
Use of AI Tools
OpenAI Codex assisted with investigation, implementation, regression tests, automated validation and this description. Additional Codex review identified the non-object compatibility case. Maintainer review is requested.
Please add
[Type] Bug; the contributor account cannot apply repository labels.