Changeset 59391
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-open-elements.php
r58992 r59391 521 521 } 522 522 523 if ( 'context-node' === $item->bookmark_name ) {524 $this->stack[] = $item;525 return false;526 }527 528 523 $this->after_element_pop( $item ); 529 524 return true; … … 586 581 */ 587 582 public function remove_node( WP_HTML_Token $token ): bool { 588 if ( 'context-node' === $token->bookmark_name ) {589 return false;590 }591 592 583 foreach ( $this->walk_up() as $position_from_end => $item ) { 593 584 if ( $token->bookmark_name !== $item->bookmark_name ) { -
trunk/src/wp-includes/html-api/class-wp-html-processor.php
r59364 r59391 5329 5329 */ 5330 5330 if ( 'backward' === $direction ) { 5331 /* 5332 * Instead of clearing the parser state and starting fresh, calling the stack methods5333 * maintains the proper flags in the parser.5331 5332 /* 5333 * When moving backward, stateful stacks should be cleared. 5334 5334 */ 5335 5335 foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) { 5336 if ( 'context-node' === $item->bookmark_name ) {5337 break;5338 }5339 5340 5336 $this->state->stack_of_open_elements->remove_node( $item ); 5341 5337 } 5342 5338 5343 5339 foreach ( $this->state->active_formatting_elements->walk_up() as $item ) { 5344 if ( 'context-node' === $item->bookmark_name ) {5345 break;5346 }5347 5348 5340 $this->state->active_formatting_elements->remove_node( $item ); 5349 5341 } 5350 5342 5351 parent::seek( 'context-node' ); 5352 $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY; 5353 $this->state->frameset_ok = true; 5354 $this->element_queue = array(); 5355 $this->current_element = null; 5356 5357 if ( isset( $this->context_node ) ) { 5343 /* 5344 * **After** clearing stacks, more processor state can be reset. 5345 * This must be done after clearing the stack because those stacks generate events that 5346 * would appear on a subsequent call to `next_token()`. 5347 */ 5348 $this->state->frameset_ok = true; 5349 $this->state->stack_of_template_insertion_modes = array(); 5350 $this->state->head_element = null; 5351 $this->state->form_element = null; 5352 $this->state->current_token = null; 5353 $this->current_element = null; 5354 $this->element_queue = array(); 5355 5356 /* 5357 * The absence of a context node indicates a full parse. 5358 * The presence of a context node indicates a fragment parser. 5359 */ 5360 if ( null === $this->context_node ) { 5361 $this->change_parsing_namespace( 'html' ); 5362 $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_INITIAL; 5363 $this->breadcrumbs = array(); 5364 5365 $this->bookmarks['initial'] = new WP_HTML_Span( 0, 0 ); 5366 parent::seek( 'initial' ); 5367 unset( $this->bookmarks['initial'] ); 5368 } else { 5369 5370 /* 5371 * Push the root-node (HTML) back onto the stack of open elements. 5372 * 5373 * Fragment parsers require this extra bit of setup. 5374 * It's handled in full parsers by advancing the processor state. 5375 */ 5376 $this->state->stack_of_open_elements->push( 5377 new WP_HTML_Token( 5378 'root-node', 5379 'HTML', 5380 false 5381 ) 5382 ); 5383 5384 $this->change_parsing_namespace( 5385 $this->context_node->integration_node_type 5386 ? 'html' 5387 : $this->context_node->namespace 5388 ); 5389 5390 if ( 'TEMPLATE' === $this->context_node->node_name ) { 5391 $this->state->stack_of_template_insertion_modes[] = WP_HTML_Processor_State::INSERTION_MODE_IN_TEMPLATE; 5392 } 5393 5394 $this->reset_insertion_mode_appropriately(); 5358 5395 $this->breadcrumbs = array_slice( $this->breadcrumbs, 0, 2 ); 5359 } else { 5360 $this->breadcrumbs = array(); 5396 parent::seek( $this->context_node->bookmark_name ); 5361 5397 } 5362 5398 } 5363 5399 5364 // When moving forwards, reparse the document until reaching the same location as the original bookmark. 5365 if ( $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) { 5366 return true; 5367 } 5368 5369 while ( $this->next_token() ) { 5400 /* 5401 * Here, the processor moves forward through the document until it matches the bookmark. 5402 * do-while is used here because the processor is expected to already be stopped on 5403 * a token than may match the bookmarked location. 5404 */ 5405 do { 5406 /* 5407 * The processor will stop on virtual tokens, but bookmarks may not be set on them. 5408 * They should not be matched when seeking a bookmark, skip them. 5409 */ 5410 if ( $this->is_virtual() ) { 5411 continue; 5412 } 5370 5413 if ( $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) { 5371 while ( isset( $this->current_element ) && WP_HTML_Stack_Event::POP === $this->current_element->operation ) {5372 $this->current_element = array_shift( $this->element_queue );5373 }5374 5414 return true; 5375 5415 } 5376 } 5416 } while ( $this->next_token() ); 5377 5417 5378 5418 return false; -
trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php
r59364 r59391 134 134 // Create a bookmark inside of that stack. 135 135 if ( null !== $processor->get_attribute( 'two' ) ) { 136 $ processor->set_bookmark( 'two');136 $this->assertTrue( $processor->set_bookmark( 'two' ) ); 137 137 break; 138 138 }
Note: See TracChangeset
for help on using the changeset viewer.