diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 71f1794c52..fb2141da46 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -238,16 +238,30 @@ function wpautop($pee, $br = true) { $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); $pee = preg_replace('!()!', "$1\n\n", $pee); $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines - if ( strpos($pee, ']*)>\s*|', "", $pee); // no pee inside object/embed - $pee = preg_replace('|\s*\s*|', '', $pee); + + if ( strpos( $pee, '' ) !== false ) { + // no P/BR around param and embed + $pee = preg_replace( '|(]*>)\s*|', '$1', $pee ); + $pee = preg_replace( '|\s*|', '', $pee ); + $pee = preg_replace( '%\s*(]*>)\s*%', '$1', $pee ); } + + if ( strpos( $pee, '\]]*[>\]])\s*%', '$1', $pee ); + $pee = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee ); + $pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee ); + } + $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates // make paragraphs, including one at the end $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY); $pee = ''; - foreach ( $pees as $tinkle ) + + foreach ( $pees as $tinkle ) { $pee .= '

' . trim($tinkle, "\n") . "

\n"; + } + $pee = preg_replace('|

\s*

|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace $pee = preg_replace('!

([^<]+)!', "

$1

", $pee); $pee = preg_replace('!

\s*(]*>)\s*

!', "$1", $pee); // don't pee all over a tag @@ -256,11 +270,13 @@ function wpautop($pee, $br = true) { $pee = str_replace('

', '

', $pee); $pee = preg_replace('!

\s*(]*>)!', "$1", $pee); $pee = preg_replace('!(]*>)\s*

!', "$1", $pee); + if ( $br ) { $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee); $pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks $pee = str_replace('', "\n", $pee); } + $pee = preg_replace('!(]*>)\s*
!', "$1", $pee); $pee = preg_replace('!
(\s*]*>)!', '$1', $pee); $pee = preg_replace( "|\n

$|", '

', $pee ); diff --git a/tests/phpunit/tests/formatting/Autop.php b/tests/phpunit/tests/formatting/Autop.php index 7cd324f985..d2f78bc17e 100644 --- a/tests/phpunit/tests/formatting/Autop.php +++ b/tests/phpunit/tests/formatting/Autop.php @@ -98,4 +98,169 @@ PS. Not yet subscribed for update notifications?
Password: '; $this->assertEquals( "

$str

", trim( wpautop( $str ) ) ); } + + /** + * wpautop() Should not add

and
around and + * + * @ticket 26864 + */ + public function test_source_track_elements() { + $content = "Paragraph one.\n\n" . + '
http://domain.tld/wp-content/uploads/2013/12/xyz.mp4 + ' . + "\n\nParagraph two."; + + $content2 = "Paragraph one.\n\n" . + '' . + "\n\nParagraph two."; + + $expected = "

Paragraph one.

\n" . // line breaks only after

+ '

\n" . + '

Paragraph two.

'; + + // When running the content through wpautop() from wp_richedit_pre() + $shortcode_content = "Paragraph one.\n\n" . + '[video width="720" height="480" mp4="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4"] + + + + + + + + + [/video]' . + "\n\nParagraph two."; + + $shortcode_expected = "

Paragraph one.

\n" . // line breaks only after

+ '

[video width="720" height="480" mp4="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4"]' . + '' . + '' . + '' . + '' . + "[/video]

\n" . + '

Paragraph two.

'; + + $this->assertEquals( $expected, trim( wpautop( $content ) ) ); + $this->assertEquals( $expected, trim( wpautop( $content2 ) ) ); + $this->assertEquals( $shortcode_expected, trim( wpautop( $shortcode_content ) ) ); + } + + /** + * wpautop() Should not add

and
around and + * + * @ticket 26864 + */ + public function test_param_embed_elements() { + $content1 = ' +Paragraph one. + + + + + + + + + + + +Paragraph two.'; + + $expected1 = "

Paragraph one.

\n" . // line breaks only after

+ '

' . + '' . + '' . + '' . + '' . + '' . + '' . + "

\n" . + '

Paragraph two.

'; + + $content2 = ' +Paragraph one. + +
+ + + + + + + + + + + + + + + + + +
+ +Paragraph two.'; + + $expected2 = "

Paragraph one.

\n" . // line breaks only after block tags + '
' . "\n" . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + "
\n" . + '

Paragraph two.

'; + + $this->assertEquals( $expected1, trim( wpautop( $content1 ) ) ); + $this->assertEquals( $expected2, trim( wpautop( $content2 ) ) ); + } } diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index e18f2a5596..dfe5d15c82 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -364,4 +364,45 @@ CONTENT; $matches = get_media_embedded_in_content( $content, $types ); $this->assertEquals( $contents, $matches ); } + + /** + * Test [video] shortcode processing + * + * @ticket 26864 + */ + function test_video_shortcode_body() { + $width = 720; + $height = 480; + + $video =<<