Verified Commit 5e71310c authored by Alex Pott's avatar Alex Pott
Browse files

fix: #2350049 filter_autop() returns <br /> but should return <br> for HTML5

By: hanno
By: legolasbo
By: smustgrave
By: catch
By: trackleft2
By: longwave
By: mkindred
By: ammaletu
By: quietone
By: larowlan
By: nod_
By: wim leers
By: joegraduate
By: alexpott
(cherry picked from commit aad4f748)
parent 6ee54f81
Loading
Loading
Loading
Loading
Loading
+4 −4
Changes for core/modules/filter/src/Plugin/Filter/FilterAutoP.php: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ public function process($text, $langcode) {

        // Just to make things a little easier, pad the end.
        $chunk = preg_replace('|\n*$|', '', $chunk) . "\n\n";
        $chunk = preg_replace('|<br />\s*<br />|', "\n\n", $chunk);
        $chunk = preg_replace('|<br ?/?>\s*<br ?/?>|', "\n\n", $chunk);
        // Space things out a little.
        $chunk = preg_replace('!(<' . $block . '[^>]*>)!', "\n$1", $chunk);
        // Space things out a little.
@@ -100,9 +100,9 @@ public function process($text, $langcode) {
        $chunk = preg_replace('!<p>\s*(</?' . $block . '[^>]*>)!', "$1", $chunk);
        $chunk = preg_replace('!(</?' . $block . '[^>]*>)\s*</p>!', "$1", $chunk);
        // Make line breaks.
        $chunk = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $chunk);
        $chunk = preg_replace('!(</?' . $block . '[^>]*>)\s*<br />!', "$1", $chunk);
        $chunk = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)!', '$1', $chunk);
        $chunk = preg_replace('|(?<!<br>)\s*\n|', "<br>\n", $chunk);
        $chunk = preg_replace('!(</?' . $block . '[^>]*>)\s*<br>!', "$1", $chunk);
        $chunk = preg_replace('!<br>(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)!', '$1', $chunk);
        $chunk = preg_replace('/&([^#])(?![A-Za-z0-9]{1,8};)/', '&amp;$1', $chunk);
      }
      $output .= $chunk;
+4 −4
Changes for core/modules/filter/tests/src/Kernel/FilterKernelTest.php: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -420,10 +420,10 @@ public function testLineBreakFilter(): void {
    // cSpell:disable
    // phpcs:disable Drupal.Arrays.Array.ArrayClosingIndentation, Drupal.Arrays.Array.ArrayIndentation
    $tests = [
      // Single line breaks should be changed to <br /> tags, while paragraphs
      // Single line breaks should be changed to <br> tags, while paragraphs
      // separated with double line breaks should be enclosed with <p></p> tags.
      "aaa\nbbb\n\nccc" => [
        "<p>aaa<br />\nbbb</p>\n<p>ccc</p>" => TRUE,
        "<p>aaa<br>\nbbb</p>\n<p>ccc</p>" => TRUE,
      ],
      // Skip contents of certain block tags entirely.
      "<script>aaa\nbbb\n\nccc</script>
@@ -470,7 +470,7 @@ public function testLineBreakFilter(): void {
      ],
      "<pre>aaa\nbbb\nccc</pre>\nddd\neee" => [
        "<pre>aaa\nbbb\nccc</pre>" => TRUE,
        "<p>ddd<br />\neee</p>" => TRUE,
        "<p>ddd<br>\neee</p>" => TRUE,
      ],
      // Comments remain unchanged and subsequent lines/paragraphs are
      // transformed normally.
@@ -1151,7 +1151,7 @@ public function testHtmlCorrectorFilter(): void {
    $this->assertEquals('<img src="http://example.com/test.jpg">test', $f, 'HTML corrector -- Fix self-closing single tags.');

    $f = Html::normalize('<br></br>');
    $this->assertEquals('<br><br>', $f, "HTML corrector -- Transform empty tags to a self-closed tag if the tag's content model is EMPTY.");
    $this->assertEquals('<br><br>', $f, "HTML corrector -- Transform empty tags into two br tags if the tag's content model is EMPTY.");

    $f = Html::normalize('<div></div>');
    $this->assertEquals('<div></div>', $f, "HTML corrector -- Do not transform empty tags to a single closed tag if the tag's content model is not EMPTY.");