Make WordPress Core

Changeset 59410


Ignore:
Timestamp:
11/18/2024 01:05:35 PM (2 months ago)
Author:
cbravobernal
Message:

HTML API: Fix normalized doctype pub/sys identifier quotes.

Changeset [59399] fixed missing DOCTYPEs in normalized HTML output. It missed an edge case where public and system identifiers may contain double quotes, in which case they must be quoted with single quotes.

This commit addresses that issue and adds tests.

Follow-up to [59399].

Props jonsurrell, luisherranz, apermo.
Fixes #62396.

Location:
trunk
Files:
2 edited

Legend:

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

    r59399 r59410  
    11921192
    11931193                if ( null !== $doctype->public_identifier ) {
    1194                     $html .= " PUBLIC \"{$doctype->public_identifier}\"";
     1194                    $quote = str_contains( $doctype->public_identifier, '"' ) ? "'" : '"';
     1195                    $html .= " PUBLIC {$quote}{$doctype->public_identifier}{$quote}";
    11951196                }
    11961197                if ( null !== $doctype->system_identifier ) {
     
    11981199                        $html .= ' SYSTEM';
    11991200                    }
    1200                     $html .= " \"{$doctype->system_identifier}\"";
    1201                 }
     1201                    $quote = str_contains( $doctype->system_identifier, '"' ) ? "'" : '"';
     1202                    $html .= " {$quote}{$doctype->system_identifier}{$quote}";
     1203                }
     1204
    12021205                $html .= '>';
    12031206                break;
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php

    r59399 r59410  
    308308    public static function data_provider_serialize_doctype() {
    309309        return array(
    310             'None'                   => array( '', '' ),
    311             'Empty'                  => array( '<!DOCTYPE>', '<!DOCTYPE>' ),
    312             'HTML5'                  => array( '<!DOCTYPE html>', '<!DOCTYPE html>' ),
    313             'Strange name'           => array( '<!DOCTYPE WordPress>', '<!DOCTYPE wordpress>' ),
    314             'With public'            => array( '<!DOCTYPE html PUBLIC "x">', '<!DOCTYPE html PUBLIC "x">' ),
    315             'With system'            => array( '<!DOCTYPE html SYSTEM "y">', '<!DOCTYPE html SYSTEM "y">' ),
    316             'With public and system' => array( '<!DOCTYPE html PUBLIC "x" "y">', '<!DOCTYPE html PUBLIC "x" "y">' ),
    317             'Weird casing'           => array( '<!docType HtmL pubLIc\'xxx\'"yyy" all this is ignored>', '<!DOCTYPE html PUBLIC "xxx" "yyy">' ),
     310            'None'                       => array( '', '' ),
     311            'Empty'                      => array( '<!DOCTYPE>', '<!DOCTYPE>' ),
     312            'HTML5'                      => array( '<!DOCTYPE html>', '<!DOCTYPE html>' ),
     313            'Strange name'               => array( '<!DOCTYPE WordPress>', '<!DOCTYPE wordpress>' ),
     314            'With public'                => array( '<!DOCTYPE html PUBLIC "x">', '<!DOCTYPE html PUBLIC "x">' ),
     315            'With system'                => array( '<!DOCTYPE html SYSTEM "y">', '<!DOCTYPE html SYSTEM "y">' ),
     316            'With public and system'     => array( '<!DOCTYPE html PUBLIC "x" "y">', '<!DOCTYPE html PUBLIC "x" "y">' ),
     317            'Weird casing'               => array( '<!docType HtmL pubLIc\'xxx\'"yyy" all this is ignored>', '<!DOCTYPE html PUBLIC "xxx" "yyy">' ),
     318            'Single quotes in public ID' => array( '<!DOCTYPE html PUBLIC "\'quoted\'">', '<!DOCTYPE html PUBLIC "\'quoted\'">' ),
     319            'Double quotes in public ID' => array( '<!DOCTYPE html PUBLIC \'"quoted"\'\>', '<!DOCTYPE html PUBLIC \'"quoted"\'>' ),
     320            'Single quotes in system ID' => array( '<!DOCTYPE html SYSTEM "\'quoted\'">', '<!DOCTYPE html SYSTEM "\'quoted\'">' ),
     321            'Double quotes in system ID' => array( '<!DOCTYPE html SYSTEM \'"quoted"\'\>', '<!DOCTYPE html SYSTEM \'"quoted"\'>' ),
    318322        );
    319323    }
Note: See TracChangeset for help on using the changeset viewer.