Formatting: Don't add `<p>` tags inside `<svg>` tags.

Inline `<svg>`s should generally work, as browsers should just ignore `<p>` or `<br/>` tags that shouldn't be inside the `<svg>`. 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
This commit is contained in:
Gary Pendergast 2019-07-01 03:18:28 +00:00
parent b87bdbe9ba
commit 77f9bf0aeb
2 changed files with 35 additions and 1 deletions

View File

@ -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 <br>
$pee = str_replace( array( '<br>', '<br/>' ), '<br />', $pee );

View File

@ -566,4 +566,38 @@ line 2<br/>
$this->assertEquals( $expected, trim( wpautop( $content ) ) );
}
/**
* wpautop() should ignore inline SVG graphics
*
* @ticket 9437
*/
function test_that_wpautop_ignores_inline_svgs() {
$content =
'<svg xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="30" fill="blue">
<animateTransform attributeName="transform" type="scale" to="1.5" dur="2s" fill="freeze"/>
</circle>
</svg>';
$expected = '<p>' . $content . '</p>';
$this->assertEquals( $expected, trim( wpautop( $content ) ) );
}
/**
* wpautop() should ignore inline scripts
*
* @ticket 9437
*/
function test_that_wpautop_ignores_inline_scripts() {
$content =
'<script type="text/javascript">
var dummy = 1;
</script>';
$expected = '<p>' . $content . '</p>';
$this->assertEquals( $expected, trim( wpautop( $content ) ) );
}
}