From 4fdc7c7a0b142a27534356645c3de9a2b64f06b1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 7 Jan 2015 07:50:58 +0000 Subject: [PATCH] Don't force newlines around URLs in WP_Embed::autoembed(). props chipx86, sgrant. fixes #23776. git-svn-id: https://develop.svn.wordpress.org/trunk@31066 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-embed.php | 6 +++--- tests/phpunit/tests/media.php | 34 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-embed.php b/src/wp-includes/class-wp-embed.php index f536f71a04..1cd4d6252c 100644 --- a/src/wp-includes/class-wp-embed.php +++ b/src/wp-includes/class-wp-embed.php @@ -311,7 +311,7 @@ class WP_Embed { * @return string Potentially modified $content. */ public function autoembed( $content ) { - return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content ); + return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); } /** @@ -323,10 +323,10 @@ class WP_Embed { public function autoembed_callback( $match ) { $oldval = $this->linkifunknown; $this->linkifunknown = false; - $return = $this->shortcode( array(), $match[1] ); + $return = $this->shortcode( array(), $match[2] ); $this->linkifunknown = $oldval; - return "\n$return\n"; + return $match[1] . $return . $match[3]; } /** diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 4523e4ee3b..f0960d7536 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -132,6 +132,40 @@ CAP; $this->assertContains( 'https://www.youtube.com/embed/zHjMoNQN7s0?feature=oembed', $out ); } + /** + * @ticket 23776 + */ + function test_autoembed_empty() { + global $wp_embed; + + $content = ''; + + $result = $wp_embed->autoembed( $content ); + $this->assertEquals( $content, $result ); + } + + /** + * @ticket 23776 + */ + function test_autoembed_no_paragraphs_around_urls() { + global $wp_embed; + + $content = <<http://some.link/ +http://some.other.link/ +EOF; + + $result = $wp_embed->autoembed( $content ); + $this->assertEquals( $content, $result ); + } + function test_wp_prepare_attachment_for_js() { // Attachment without media $id = wp_insert_attachment(array(