Make WordPress Core


Ignore:
Timestamp:
09/27/2024 12:42:47 AM (18 months ago)
Author:
dmsnell
Message:

HTML API: Switch to HTML namespace when entering Integration Points.

When encountering inline SVG and MathML content in an HTML document, there are certain "integration points" which transition back into the HTML parsing ruleset. Previously, the HTML API was incorrectly switching into the namespace of the element transitioning into that ruleset.

In this patch, the correct transition is made, where all integration points refer to HTML rules, while non-integration points refer to the rules of the namespace corresponding to the token itself.

Developed in https://github.com/wordpress/wordpress-develop/pull/7425
Discussed in https://core.trac.wordpress.org/ticket/61576

Props dmsnell, jonsurrell.
See #61576.

File:
1 edited

Legend:

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

    r59076 r59099  
    394394                $this->element_queue[] = new WP_HTML_Stack_Event( $token, WP_HTML_Stack_Event::PUSH, $provenance );
    395395
    396                 $this->change_parsing_namespace( $token->namespace );
     396                $this->change_parsing_namespace( $token->integration_node_type ? 'html' : $token->namespace );
    397397            }
    398398        );
     
    404404                $provenance            = ( ! $same_node || $is_virtual ) ? 'virtual' : 'real';
    405405                $this->element_queue[] = new WP_HTML_Stack_Event( $token, WP_HTML_Stack_Event::POP, $provenance );
     406
    406407                $adjusted_current_node = $this->get_adjusted_current_node();
    407                 $this->change_parsing_namespace(
    408                     $adjusted_current_node
    409                         ? $adjusted_current_node->namespace
    410                         : 'html'
    411                 );
     408
     409                if ( $adjusted_current_node ) {
     410                    $this->change_parsing_namespace( $adjusted_current_node->integration_node_type ? 'html' : $adjusted_current_node->namespace );
     411                } else {
     412                    $this->change_parsing_namespace( 'html' );
     413                }
    412414            }
    413415        );
Note: See TracChangeset for help on using the changeset viewer.