WordPress.org

Make WordPress Core

Ticket #33645: 33645.patch

File 33645.patch, 1.9 KB (added by miqrogroove, 5 years ago)

Fixes newlines around objects. Fixes confusion of P and PARAM. Adds unit test.

  • src/wp-includes/formatting.php

     
    496496        $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    497497
    498498        // Add a single line break above block-level opening tags.
    499         $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
     499        $pee = preg_replace('!(<' . $allblocks . '(?:>|\s[^>]*>))!', "\n$1", $pee);
    500500
    501501        // Add a double line break below block-level closing tags.
    502502        $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
     
    596596                $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
    597597
    598598        // Restore newlines in all elements.
    599         $pee = str_replace( " <!-- wpnl --> ", "\n", $pee );
     599        if ( false !== strpos( $pee, " <!-- wpnl --> " ) ) {
     600                $pee = str_replace( " <!-- wpnl --> ", "\n", $pee );
     601        }
     602        if ( false !== strpos( $pee, "<!-- wpnl -->" ) ) {
     603                $pee = str_replace( "<!-- wpnl -->", "\n", $pee );
     604        }
    600605
    601606        return $pee;
    602607}
  • tests/phpunit/tests/formatting/Autop.php

     
    420420                                "Hello <!-- a\nhref='world' -->",
    421421                                "<p>Hello <!-- a\nhref='world' --></p>\n",
    422422                        ),
     423                        array(
     424                                "Hello <!-- <object>\n<param>\n<param>\n<embed>\n</embed>\n</object>\n -->",
     425                                "<p>Hello <!-- <object>\n<param>\n<param>\n<embed>\n</embed>\n</object>\n --></p>\n",
     426                        ),
    423427/* Block elements inside comments will fail this test in all versions, it's not a regression.
    424428                        array(
    425429                                "Hello <!-- <hr> a\nhref='world' -->",