Make WordPress Core

Ticket #25387: 25387.patch

File 25387.patch, 2.2 KB (added by iseulde, 9 years ago)
  • src/wp-includes/class-wp-embed.php

     
    336336
    337337                // Find URLs that are on their own line.
    338338                $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
     339                $content = preg_replace_callback( '|(<p[^>]*>\s*)(https?://[^\s<]+)(\s*<\/p>)|i', array( $this, 'autoembed_callback' ), $content );
    339340
    340341                // Put the line breaks back.
    341342                return str_replace( '<!-- wp-line-break -->', "\n", $content );
  • tests/phpunit/tests/media.php

     
    158158                $this->assertEquals( $content, $result );
    159159        }
    160160
     161        function data_autoembed() {
     162                return array(
     163
     164                        // Should embed
     165                        array(
     166'https://w.org',
     167'[embed]'
     168                        ),
     169                        array(
     170'test
     171 https://w.org
     172test',
     173'test
     174 [embed]
     175test'
     176                        ),
     177                        array(
     178'<p class="test">https://w.org</p>',
     179'<p class="test">[embed]</p>'
     180                        ),
     181                        array(
     182'<p> https://w.org </p>',
     183'<p> [embed] </p>'
     184                        ),
     185                        array(
     186'<p>test
     187https://w.org
     188test</p>',
     189'<p>test
     190[embed]
     191test</p>'
     192                        ),
     193
     194                        // Should NOT embed
     195                        array(
     196'test https://w.org</p>'
     197                        ),
     198                        array(
     199'<span>https://w.org</a>'
     200                        ),
     201                        array(
     202'<a href=" https://w.org ">
     203https://w.org
     204</a>'
     205                        )
     206                );
     207        }
     208
     209        /**
     210         * @dataProvider data_autoembed
     211         */
     212        function test_autoembed( $content, $result = null ) {
     213                $wp_embed = new Test_Autoembed;
     214
     215                $this->assertEquals( $wp_embed->autoembed( $content ), $result ? $result : $content );
     216        }
     217
    161218        function test_wp_prepare_attachment_for_js() {
    162219                // Attachment without media
    163220                $id = wp_insert_attachment(array(
     
    16121669                $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) );
    16131670        }
    16141671}
     1672
     1673/**
     1674 * Helper class for `test_autoembed`.
     1675 */
     1676class Test_Autoembed extends WP_Embed {
     1677        public function shortcode( $attr, $url = '' ) {
     1678                return '[embed]';
     1679        }
     1680}