WordPress.org

Make WordPress Core

Changeset 45589


Ignore:
Timestamp:
07/02/2019 11:21:53 AM (17 months ago)
Author:
pento
Message:

Formatting: Revert the changes to wpautop() in [45585,45587].

See #27350.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r45587 r45589  
    493493    $pee = preg_replace( '|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee );
    494494
    495     $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)\b';
    496     $allblocksexceptp = str_replace( '|p|', '|', $allblocks );
     495    $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)';
    497496
    498497    // Add a double line break above block-level opening tags.
     
    560559    $pee = preg_replace( '|<p>\s*</p>|', '', $pee );
    561560
     561    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
     562    $pee = preg_replace( '!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $pee );
     563
    562564    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    563565    $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee );
    564 
    565     // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    566     $pee = preg_replace( '!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $pee );
    567566
    568567    // In some cases <li> may get wrapped in <p>, fix them.
     
    578577    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    579578    $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee );
    580 
    581     // If a closing <p> tag is inside a block element tag, without a preceding opening <p> tag, remove it.
    582     $pee = preg_replace( '#(<(' . $allblocksexceptp . ')[^>]*>)(((?!<p>|</\2>).)*)</p>#s', '$1$3', $pee );
    583 
    584     // If an opening <p> tag is inside a block element tag, without a following closing <p> tag, remove it.
    585     $pee = preg_replace( '#<p>([^<]*(((?!</p>).)*)</' . $allblocksexceptp . '>)#s', '$1', $pee );
    586579
    587580    // Optionally insert line breaks.
  • trunk/tests/phpunit/tests/formatting/Autop.php

    r45588 r45589  
    603603        $this->assertEquals( $expected, trim( wpautop( $content ) ) );
    604604    }
    605 
    606     /**
    607      * wpautop() should remove stray <p> and </p> tags inside blocks
    608      *
    609      * @ticket 27350
    610      * @dataProvider data_wpautop_removes_stray_p_tags_in_blocks
    611      */
    612     function test_wpautop_removes_stray_p_tags_in_blocks( $data, $expected ) {
    613         $this->assertEquals( $expected, wpautop( $data ) );
    614     }
    615 
    616     function data_wpautop_removes_stray_p_tags_in_blocks() {
    617         return array(
    618             array(
    619                 '<div><p>123</p> </div>',
    620                 "<div>\n<p>123</p>\n</div>\n",
    621             ),
    622             array(
    623                 '<div><p>123</p></div>',
    624                 "<div>\n<p>123</p>\n</div>\n",
    625             ),
    626             array(
    627                 'hello<div>test</div>',
    628                 "<p>hello</p>\n<div>test</div>\n",
    629             ),
    630             array(
    631                 '<div><p>Hello world</p><span>WordPress</span></div>',
    632                 "<div>\n<p>Hello world</p>\n<span>WordPress</span></div>\n",
    633             ),
    634             array(
    635                 "<div>hello\n<pre>test</pre>\nworld</div>",
    636                 "<div>hello\n<pre>test</pre>\n<p>world</p></div>\n",
    637             ),
    638             array(
    639                 'hello<div>test</div>',
    640                 "<p>hello</p>\n<div>test</div>\n",
    641             ),
    642             array(
    643                 '<div><img src="/wp-content/uploads/example.jpg" alt="something" /><div>Something</div></div>',
    644                 "<div><img src=\"/wp-content/uploads/example.jpg\" alt=\"something\" />\n<div>Something</div>\n</div>\n",
    645             ),
    646             array(
    647                 '<div><span></span><div></div></div>',
    648                 "<div><span></span>\n<div></div>\n</div>\n",
    649             ),
    650             array(
    651                 '<div>X<div></div></div>',
    652                 "<div>X\n<div></div>\n</div>\n",
    653             ),
    654             array(
    655                 "<div><div></div>\n </div>",
    656                 "<div>\n<div></div>\n</div>\n",
    657             ),
    658             array(
    659                 "[banner]\n<h1>Test</h1>",
    660                 "<p>[banner]</p>\n<h1>Test</h1>\n",
    661             ),
    662         );
    663     }
    664605}
Note: See TracChangeset for help on using the changeset viewer.