From 77f9bf0aebb5f82da040dbd21cb11572fa850c4f Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Mon, 1 Jul 2019 03:18:28 +0000 Subject: [PATCH] Formatting: Don't add `

` tags inside `` tags. Inline ``s should generally work, as browsers should just ignore `

` or `
` tags that shouldn't be inside the ``. To keep things neat, however, it's better not add them in the first place. Props jared_smith, nacin, pento. Fixes #9437. git-svn-id: https://develop.svn.wordpress.org/trunk@45577 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 2 +- tests/phpunit/tests/formatting/Autop.php | 34 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index e2c8aef269..be27b07ca6 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -580,7 +580,7 @@ function wpautop( $pee, $br = true ) { // Optionally insert line breaks. if ( $br ) { // Replace newlines that shouldn't be touched with a placeholder. - $pee = preg_replace_callback( '/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee ); + $pee = preg_replace_callback( '/<(script|style|svg).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee ); // Normalize
$pee = str_replace( array( '
', '
' ), '
', $pee ); diff --git a/tests/phpunit/tests/formatting/Autop.php b/tests/phpunit/tests/formatting/Autop.php index 405b68ad34..e93e826695 100644 --- a/tests/phpunit/tests/formatting/Autop.php +++ b/tests/phpunit/tests/formatting/Autop.php @@ -566,4 +566,38 @@ line 2
$this->assertEquals( $expected, trim( wpautop( $content ) ) ); } + + /** + * wpautop() should ignore inline SVG graphics + * + * @ticket 9437 + */ + function test_that_wpautop_ignores_inline_svgs() { + $content = + ' + + + + '; + + $expected = '

' . $content . '

'; + + $this->assertEquals( $expected, trim( wpautop( $content ) ) ); + } + + /** + * wpautop() should ignore inline scripts + * + * @ticket 9437 + */ + function test_that_wpautop_ignores_inline_scripts() { + $content = + ''; + + $expected = '

' . $content . '

'; + + $this->assertEquals( $expected, trim( wpautop( $content ) ) ); + } }