Make WordPress Core


Ignore:
Timestamp:
09/11/2024 04:11:32 PM (9 months ago)
Author:
dmsnell
Message:

HTML API: Make WP_HTML_Processor::get_tag() namespace aware.

The HTML specification indicates that an HTML tag with the name "IMAGE"
should be renamed as "IMG" and handled as if it were an "IMG", but this
only applies to elements in the HTML namespace.

In this patch the HTML Processor is updated to ensure that it doesn't
remap the tag name when processing foreign content, such as SVG and
MathML markup.

Developed in https://github.com/wordpress/wordpress-develop/7330
Discussed in https://core.trac.wordpress.org/ticket/61656

Props dmsnell, jonsurrell.
See #61576.

File:
1 edited

Legend:

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

    r59001 r59014  
    47284728        $tag_name = parent::get_tag();
    47294729
    4730         switch ( $tag_name ) {
    4731             case 'IMAGE':
    4732                 /*
    4733                  * > A start tag whose tag name is "image"
    4734                  * > Change the token's tag name to "img" and reprocess it. (Don't ask.)
    4735                  */
    4736                 return 'IMG';
    4737 
    4738             default:
    4739                 return $tag_name;
    4740         }
     4730        /*
     4731         * > A start tag whose tag name is "image"
     4732         * > Change the token's tag name to "img" and reprocess it. (Don't ask.)
     4733         */
     4734        return ( 'IMAGE' === $tag_name && 'html' === $this->get_namespace() )
     4735            ? 'IMG'
     4736            : $tag_name;
    47414737    }
    47424738
Note: See TracChangeset for help on using the changeset viewer.