Make WordPress Core

Changeset 31066


Ignore:
Timestamp:
01/07/2015 07:50:58 AM (12 years ago)
Author:
SergeyBiryukov
Message:

Don't force newlines around URLs in WP_Embed::autoembed().

props chipx86, sgrant.
fixes #23776.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-embed.php

    r31034 r31066  
    312312         */
    313313        public function autoembed( $content ) {
    314                 return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );
     314                return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
    315315        }
    316316
     
    324324                $oldval = $this->linkifunknown;
    325325                $this->linkifunknown = false;
    326                 $return = $this->shortcode( array(), $match[1] );
     326                $return = $this->shortcode( array(), $match[2] );
    327327                $this->linkifunknown = $oldval;
    328328
    329                 return "\n$return\n";
     329                return $match[1] . $return . $match[3];
    330330        }
    331331
  • trunk/tests/phpunit/tests/media.php

    r30640 r31066  
    131131                $out = wp_oembed_get( 'https://youtu.be/zHjMoNQN7s0' );
    132132                $this->assertContains( 'https://www.youtube.com/embed/zHjMoNQN7s0?feature=oembed', $out );
     133        }
     134
     135        /**
     136         * @ticket 23776
     137         */
     138        function test_autoembed_empty() {
     139                global $wp_embed;
     140
     141                $content = '';
     142
     143                $result = $wp_embed->autoembed( $content );
     144                $this->assertEquals( $content, $result );
     145        }
     146
     147        /**
     148         * @ticket 23776
     149         */
     150        function test_autoembed_no_paragraphs_around_urls() {
     151                global $wp_embed;
     152
     153                $content = <<<EOF
     154$ my command
     155First line.
     156
     157http://example.com/1/
     158http://example.com/2/
     159Last line.
     160
     161<pre>http://some.link/
     162http://some.other.link/</pre>
     163EOF;
     164
     165                $result = $wp_embed->autoembed( $content );
     166                $this->assertEquals( $content, $result );
    133167        }
    134168
Note: See TracChangeset for help on using the changeset viewer.