Opened 7 weeks ago
Closed 6 weeks ago
#64751 closed defect (bug) (fixed)
::set_modifiable_text() should only work on atomic elements in the HTML namespace
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | minor | Version: | 6.7 |
| Component: | HTML API | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
::set_modifiable_text() includes special handling to allow setting the text of certain special "atomic" elements. These elements all have special parsing rules in the HTML standard.
The special handling should only apply to elements in the HTML namespace. The special handling only checks the tag names.
For example, this is correct:
<?php $p = WP_HTML_Processor::create_fragment('<textarea></textarea>'); $p->next_tag(); echo "{$p->get_namespace()}:{$p->get_tag()}\n"; assert( $p->set_modifiable_text('hello') ); echo $p->get_updated_html();
Prints:
html:TEXTAREA <textarea>hello</textarea>
The following attempts to set the text on svg:textarea. This should fail and return false:
<?php $p = WP_HTML_Processor::create_fragment('<svg><textarea></textarea></svg>'); $p->next_tag(); $p->next_tag(); echo "{$p->get_namespace()}:{$p->get_tag()}\n"; assert( $p->set_modifiable_text('whoops!') ); // this assertion should fail! echo $p->get_updated_html();
Instead, it adds the text to the beginning of the HTML:
svg:TEXTAREA whoops!<svg><textarea></textarea></svg>
::get_modifiable_text() should behave similarly. It does not appear to have any issues although it does not explicitly check the HTML namespace.
Change History (4)
This ticket was mentioned in PR #11083 on WordPress/wordpress-develop by @jonsurrell.
7 weeks ago
#1
- Keywords has-patch has-unit-tests added
@westonruter commented on PR #11083:
6 weeks ago
#2
I see my suggestions would also apply to r61754.
@jonsurrell commented on PR #11083:
6 weeks ago
#3
I see my suggestions would also apply to r61754.
I pushed dc65bb38960bf63a191f8e3a1d125c7ac66bbfe1 to update those test types in this PR.
Ensure the the HTML API does not attempt to set modifiable text on a foreign element tag. This could happen in foreign content when the tag name matches a special "atomic" HTML element, like
SCRIPTorTEXTAREA.Trac ticket: https://core.trac.wordpress.org/ticket/64751
## Use of AI Tools