Make WordPress Core


Ignore:
Timestamp:
11/13/2024 04:13:52 PM (3 months ago)
Author:
cbravobernal
Message:

HTML API: Include doctype in full parser serialize.

Output DOCTYPE when calling WP_HTML_Processor::serialize on a full document that includes a DOCTYPE.

The DOCTYPE should be included in the serialized/normalized HTML output as it has an impact in how the document is handled, in particular whether the document should be handled in quirks or no-quirks mode.

This only affects the serialization of full parsers at this time because DOCTYPE tokens are currently ignored in all possible fragments. The omission of the DOCTYPE is subtle but can change the serialized document's quirks/no-quirks mode.

Reviewed by cbravobernal.
Merges [59399] to the 6.7 branch.

Props jonsurrell.
Fixes #62396.

Location:
branches/6.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.7

  • branches/6.7/src/wp-includes/html-api/class-wp-html-processor.php

    r59248 r59401  
    11581158
    11591159        switch ( $token_type ) {
     1160            case '#doctype':
     1161                $doctype = $this->get_doctype_info();
     1162                if ( null === $doctype ) {
     1163                    break;
     1164                }
     1165
     1166                $html .= '<!DOCTYPE';
     1167
     1168                if ( $doctype->name ) {
     1169                    $html .= " {$doctype->name}";
     1170                }
     1171
     1172                if ( null !== $doctype->public_identifier ) {
     1173                    $html .= " PUBLIC \"{$doctype->public_identifier}\"";
     1174                }
     1175                if ( null !== $doctype->system_identifier ) {
     1176                    if ( null === $doctype->public_identifier ) {
     1177                        $html .= ' SYSTEM';
     1178                    }
     1179                    $html .= " \"{$doctype->system_identifier}\"";
     1180                }
     1181                $html .= '>';
     1182                break;
     1183
    11601184            case '#text':
    11611185                $html .= htmlspecialchars( $this->get_modifiable_text(), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, 'UTF-8' );
     
    11731197            case '#cdata-section':
    11741198                $html .= "<![CDATA[{$this->get_modifiable_text()}]]>";
    1175                 break;
    1176 
    1177             case 'html':
    1178                 $html .= '<!DOCTYPE html>';
    11791199                break;
    11801200        }
Note: See TracChangeset for help on using the changeset viewer.