Skip to content

Commit

Permalink
Work on fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Oct 25, 2024
1 parent 2313f37 commit f9e9334
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
72 changes: 47 additions & 25 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5286,6 +5286,8 @@ public function seek( $bookmark_name ): bool {
// Flush any pending updates to the document before beginning.
$this->get_updated_html();

echo 'Seeking to ' . $bookmark_name . "\n";

$actual_bookmark_name = "_{$bookmark_name}";
$processor_started_at = $this->state->current_token
? $this->bookmarks[ $this->state->current_token->bookmark_name ]->start
Expand Down Expand Up @@ -5323,45 +5325,64 @@ public function seek( $bookmark_name ): bool {
* and computation time.
*/
if ( 'backward' === $direction ) {
/*
* Instead of clearing the parser state and starting fresh, calling the stack methods
* maintains the proper flags in the parser.
*/
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
if ( 'context-node' === $item->bookmark_name ) {
break;
}
echo 'back: ' . "\n";
// Reset necessary parser state
$this->state->frameset_ok = true;
$this->state->stack_of_template_insertion_modes = array();
$this->state->head_element = null;
$this->state->form_element = null;
$this->state->current_token = null;
$this->element_queue = array();
$this->current_element = null;

if ( null === $this->context_node ) {
echo 'full parser' . "\n";
/*
* In the case of a full parser, the processor needs to be
* reset to a clean state and start over.
*/
$this->state->stack_of_open_elements = new WP_HTML_Open_Elements();
$this->state->active_formatting_elements = new WP_HTML_Active_Formatting_Elements();

$this->state->stack_of_open_elements->remove_node( $item );
}
$this->breadcrumbs = array();
$this->bytes_already_parsed = 0;
$this->parser_state = self::STATE_READY;
} else {
/*
* In case the parser is a fragment parser, instead of clearing the
* parser state and starting fresh, calling the stack methods
* maintains the proper flags in the parser.
*/
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
if ( 'context-node' === $item->bookmark_name ) {
break;
}

foreach ( $this->state->active_formatting_elements->walk_up() as $item ) {
if ( 'context-node' === $item->bookmark_name ) {
break;
$this->state->stack_of_open_elements->remove_node( $item );
}

$this->state->active_formatting_elements->remove_node( $item );
}
foreach ( $this->state->active_formatting_elements->walk_up() as $item ) {
if ( 'context-node' === $item->bookmark_name ) {
break;
}

parent::seek( 'context-node' );
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
$this->state->frameset_ok = true;
$this->element_queue = array();
$this->current_element = null;
$this->state->active_formatting_elements->remove_node( $item );
}

if ( isset( $this->context_node ) ) {
$this->breadcrumbs = array_slice( $this->breadcrumbs, 0, 2 );
} else {
$this->breadcrumbs = array();
parent::seek( 'context-node' );
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
$this->breadcrumbs = array_slice( $this->breadcrumbs, 0, 2 );
}
}

Check failure on line 5377 in src/wp-includes/html-api/class-wp-html-processor.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Functions must not contain multiple empty lines in a row; found 2 empty lines

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

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

echo 'false' . "\n";

Check failure on line 5394 in src/wp-includes/html-api/class-wp-html-processor.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Line indented incorrectly; expected at least 2 tabs, found 1
return false;
}

Expand Down
5 changes: 4 additions & 1 deletion src/wp-includes/html-api/class-wp-html-tag-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ class WP_HTML_Tag_Processor {
* @since 6.2.0
* @var int
*/
private $bytes_already_parsed = 0;
protected $bytes_already_parsed = 0;

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

var_dump( $was_at, $this->parser_state );

// Don't proceed if there's nothing more to scan.
if (
self::STATE_COMPLETE === $this->parser_state ||
Expand Down Expand Up @@ -2542,6 +2544,7 @@ public function has_bookmark( $bookmark_name ): bool {
* @return bool Whether the internal cursor was successfully moved to the bookmark's location.
*/
public function seek( $bookmark_name ): bool {
var_dump( $bookmark_name, $this->bookmarks );
if ( ! array_key_exists( $bookmark_name, $this->bookmarks ) ) {
_doing_it_wrong(
__METHOD__,
Expand Down

0 comments on commit f9e9334

Please sign in to comment.