From 14df09ba2cf8dca3a8ae6d94fd0c7ea6bfb1b1d4 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 15 Feb 2018 14:36:41 -0500 Subject: [PATCH] Framework: Strip comment demarcations in content filtering (#5042) --- lib/blocks.php | 3 +++ phpunit/class-do-blocks-test.php | 25 ++++++++++++++++++++++++ phpunit/fixtures/do-blocks-expected.html | 12 ++++++++++++ phpunit/fixtures/do-blocks-original.html | 17 ++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 phpunit/class-do-blocks-test.php create mode 100644 phpunit/fixtures/do-blocks-expected.html create mode 100644 phpunit/fixtures/do-blocks-original.html diff --git a/lib/blocks.php b/lib/blocks.php index 1d7b76773d8ee..e28971bad032c 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -199,6 +199,9 @@ function do_blocks( $content ) { // Append remaining unmatched content. $rendered_content .= $content; + // Strip remaining block comment demarcations. + $rendered_content = preg_replace( '/\r?\n?/m', '', $rendered_content ); + return $rendered_content; } add_filter( 'the_content', 'do_blocks', 9 ); // BEFORE do_shortcode(). diff --git a/phpunit/class-do-blocks-test.php b/phpunit/class-do-blocks-test.php new file mode 100644 index 0000000000000..ec7cd97c39bbd --- /dev/null +++ b/phpunit/class-do-blocks-test.php @@ -0,0 +1,25 @@ +assertEquals( $expected_html, $actual_html ); + } +} diff --git a/phpunit/fixtures/do-blocks-expected.html b/phpunit/fixtures/do-blocks-expected.html new file mode 100644 index 0000000000000..89781ba3d3187 --- /dev/null +++ b/phpunit/fixtures/do-blocks-expected.html @@ -0,0 +1,12 @@ +

First Auto Paragraph

+ + + +

First Gutenberg Paragraph

+ +

Second Auto Paragraph

+ + +

Third Gutenberg Paragraph

+ +

Third Auto Paragraph

diff --git a/phpunit/fixtures/do-blocks-original.html b/phpunit/fixtures/do-blocks-original.html new file mode 100644 index 0000000000000..3707e7a857910 --- /dev/null +++ b/phpunit/fixtures/do-blocks-original.html @@ -0,0 +1,17 @@ +

First Auto Paragraph

+ + + + +

First Gutenberg Paragraph

+ + +

Second Auto Paragraph

+ + + + +

Third Gutenberg Paragraph

+ + +

Third Auto Paragraph