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
This commit is contained in:
Sergey Biryukov 2015-01-07 07:50:58 +00:00
parent 2fcd588983
commit 4fdc7c7a0b
2 changed files with 37 additions and 3 deletions

View File

@ -311,7 +311,7 @@ class WP_Embed {
* @return string Potentially modified $content. * @return string Potentially modified $content.
*/ */
public function autoembed( $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 ) { public function autoembed_callback( $match ) {
$oldval = $this->linkifunknown; $oldval = $this->linkifunknown;
$this->linkifunknown = false; $this->linkifunknown = false;
$return = $this->shortcode( array(), $match[1] ); $return = $this->shortcode( array(), $match[2] );
$this->linkifunknown = $oldval; $this->linkifunknown = $oldval;
return "\n$return\n"; return $match[1] . $return . $match[3];
} }
/** /**

View File

@ -132,6 +132,40 @@ CAP;
$this->assertContains( 'https://www.youtube.com/embed/zHjMoNQN7s0?feature=oembed', $out ); $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 = <<<EOF
$ my command
First line.
http://example.com/1/
http://example.com/2/
Last line.
<pre>http://some.link/
http://some.other.link/</pre>
EOF;
$result = $wp_embed->autoembed( $content );
$this->assertEquals( $content, $result );
}
function test_wp_prepare_attachment_for_js() { function test_wp_prepare_attachment_for_js() {
// Attachment without media // Attachment without media
$id = wp_insert_attachment(array( $id = wp_insert_attachment(array(