[wp-trac] [WordPress Trac] #62241: HTML API: Fix the position update after changing the modifiable text when length differs
WordPress Trac
noreply at wordpress.org
Thu Oct 17 10:29:57 UTC 2024
#62241: HTML API: Fix the position update after changing the modifiable text when
length differs
--------------------------+--------------------
Reporter: gziolo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.7
Component: HTML API | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+--------------------
Reported by @zieladam on GitHub: https://github.com/WordPress/wordpress-
develop/pull/7007#issuecomment-2412540433
>I just isolated the problem:
>
> {{{
> #!php
> $p = new WP_HTML_Tag_Processor('Hello there');
> $p->next_token();
> $p->set_modifiable_text('Short');
> echo $p->get_updated_html();
> }}}
>
> It's not occurring with this patch:
>
> {{{
> #!diff
> - $this->bytes_already_parsed = $before_current_tag;
> + if ($this->get_token_type() === '#tag') {
> + $this->bytes_already_parsed = $before_current_tag;
> + }
> }}}
The actual fix will be more nuanced because the text node might appear in
the HTML in the middle or at the end of the HTML provided, examples:
{{{
<p>Hello</p>String to replace
}}}
{{{
<p>Hello</p>String to replace<p>Hello</p>
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62241>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list