Make WordPress Core

Changeset 55675


Ignore:
Timestamp:
04/21/2023 01:30:11 PM (3 years ago)
Author:
zieladam
Message:

HTML API: Fix a case where updates are overlooked when seeking to earlier locations.

This retains the WP_HTML_Tag_Processor attribute updates applied before calling seek() – they were erroneously erased in some cases.

Props dmsnell.
Fixes #58160.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    r55674 r55675  
    21432143                 */
    21442144                if ( $requires_no_updating && $this->bytes_already_copied > 0 ) {
     2145                        $this->html                 = $this->output_buffer . substr( $this->html, $this->bytes_already_copied );
     2146                        $this->bytes_already_copied = strlen( $this->output_buffer );
    21452147                        return $this->output_buffer . substr( $this->html, $this->bytes_already_copied );
    21462148                }
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

    r55667 r55675  
    458458
    459459        /**
     460         * Ensures that when seeking to an earlier spot in the document that
     461         * all previously-enqueued updates are applied as they ought to be.
     462         *
     463         * @ticket 58160
     464         */
     465        public function test_get_updated_html_applies_updates_to_content_after_seeking_to_before_parsed_bytes() {
     466                $p = new WP_HTML_Tag_Processor( '<div><img hidden></div>' );
     467
     468                $p->next_tag();
     469                $p->set_attribute( 'wonky', true );
     470                $p->next_tag();
     471                $p->set_bookmark( 'here' );
     472
     473                $p->next_tag( array( 'tag_closers' => 'visit' ) );
     474                $p->seek( 'here' );
     475
     476                $this->assertSame( '<div wonky><img hidden></div>', $p->get_updated_html() );
     477        }
     478
     479        /**
    460480         * @ticket 56299
    461481         *
Note: See TracChangeset for help on using the changeset viewer.