Skip to content

Commit 5d75bb7

Browse files
committed
Work on fix
1 parent f9777aa commit 5d75bb7

2 files changed

Lines changed: 51 additions & 26 deletions

File tree

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5286,6 +5286,8 @@ public function seek( $bookmark_name ): bool {
52865286
// Flush any pending updates to the document before beginning.
52875287
$this->get_updated_html();
52885288

5289+
echo 'Seeking to ' . $bookmark_name . "\n";
5290+
52895291
$actual_bookmark_name = "_{$bookmark_name}";
52905292
$processor_started_at = $this->state->current_token
52915293
? $this->bookmarks[ $this->state->current_token->bookmark_name ]->start
@@ -5323,45 +5325,64 @@ public function seek( $bookmark_name ): bool {
53235325
* and computation time.
53245326
*/
53255327
if ( 'backward' === $direction ) {
5326-
/*
5327-
* Instead of clearing the parser state and starting fresh, calling the stack methods
5328-
* maintains the proper flags in the parser.
5329-
*/
5330-
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
5331-
if ( 'context-node' === $item->bookmark_name ) {
5332-
break;
5333-
}
5328+
echo 'back: ' . "\n";
5329+
// Reset necessary parser state
5330+
$this->state->frameset_ok = true;
5331+
$this->state->stack_of_template_insertion_modes = array();
5332+
$this->state->head_element = null;
5333+
$this->state->form_element = null;
5334+
$this->state->current_token = null;
5335+
$this->element_queue = array();
5336+
$this->current_element = null;
5337+
5338+
if ( null === $this->context_node ) {
5339+
echo 'full parser' . "\n";
5340+
/*
5341+
* In the case of a full parser, the processor needs to be
5342+
* reset to a clean state and start over.
5343+
*/
5344+
$this->state->stack_of_open_elements = new WP_HTML_Open_Elements();
5345+
$this->state->active_formatting_elements = new WP_HTML_Active_Formatting_Elements();
53345346

5335-
$this->state->stack_of_open_elements->remove_node( $item );
5336-
}
5347+
$this->breadcrumbs = array();
5348+
$this->bytes_already_parsed = 0;
5349+
$this->parser_state = self::STATE_READY;
5350+
} else {
5351+
/*
5352+
* In case the parser is a fragment parser, instead of clearing the
5353+
* parser state and starting fresh, calling the stack methods
5354+
* maintains the proper flags in the parser.
5355+
*/
5356+
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
5357+
if ( 'context-node' === $item->bookmark_name ) {
5358+
break;
5359+
}
53375360

5338-
foreach ( $this->state->active_formatting_elements->walk_up() as $item ) {
5339-
if ( 'context-node' === $item->bookmark_name ) {
5340-
break;
5361+
$this->state->stack_of_open_elements->remove_node( $item );
53415362
}
53425363

5343-
$this->state->active_formatting_elements->remove_node( $item );
5344-
}
5364+
foreach ( $this->state->active_formatting_elements->walk_up() as $item ) {
5365+
if ( 'context-node' === $item->bookmark_name ) {
5366+
break;
5367+
}
53455368

5346-
parent::seek( 'context-node' );
5347-
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
5348-
$this->state->frameset_ok = true;
5349-
$this->element_queue = array();
5350-
$this->current_element = null;
5369+
$this->state->active_formatting_elements->remove_node( $item );
5370+
}
53515371

5352-
if ( isset( $this->context_node ) ) {
5353-
$this->breadcrumbs = array_slice( $this->breadcrumbs, 0, 2 );
5354-
} else {
5355-
$this->breadcrumbs = array();
5372+
parent::seek( 'context-node' );
5373+
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
5374+
$this->breadcrumbs = array_slice( $this->breadcrumbs, 0, 2 );
53565375
}
53575376
}
53585377

5378+
53595379
// When moving forwards, reparse the document until reaching the same location as the original bookmark.
5360-
if ( $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) {
5380+
if ( null !== $this->state->current_token && $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) {
53615381
return true;
53625382
}
53635383

53645384
while ( $this->next_token() ) {
5385+
echo 'bm starts at ' . $bookmark_starts_at . ' and current token starts at ' . $this->bookmarks[ $this->state->current_token->bookmark_name ]->start . "\n";
53655386
if ( $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) {
53665387
while ( isset( $this->current_element ) && WP_HTML_Stack_Event::POP === $this->current_element->operation ) {
53675388
$this->current_element = array_shift( $this->element_queue );
@@ -5370,6 +5391,7 @@ public function seek( $bookmark_name ): bool {
53705391
}
53715392
}
53725393

5394+
echo 'false' . "\n";
53735395
return false;
53745396
}
53755397

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ class WP_HTML_Tag_Processor {
591591
* @since 6.2.0
592592
* @var int
593593
*/
594-
private $bytes_already_parsed = 0;
594+
protected $bytes_already_parsed = 0;
595595

596596
/**
597597
* Byte offset in input document where current token starts.
@@ -946,6 +946,8 @@ private function base_class_next_token(): bool {
946946
$was_at = $this->bytes_already_parsed;
947947
$this->after_tag();
948948

949+
var_dump( $was_at, $this->parser_state );
950+
949951
// Don't proceed if there's nothing more to scan.
950952
if (
951953
self::STATE_COMPLETE === $this->parser_state ||
@@ -2542,6 +2544,7 @@ public function has_bookmark( $bookmark_name ): bool {
25422544
* @return bool Whether the internal cursor was successfully moved to the bookmark's location.
25432545
*/
25442546
public function seek( $bookmark_name ): bool {
2547+
var_dump( $bookmark_name, $this->bookmarks );
25452548
if ( ! array_key_exists( $bookmark_name, $this->bookmarks ) ) {
25462549
_doing_it_wrong(
25472550
__METHOD__,

0 commit comments

Comments
 (0)