Ticket #25387: 25387.4.patch
File 25387.4.patch, 2.6 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-embed.php
334 334 // Replace line breaks from all HTML elements with placeholders. 335 335 $content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) ); 336 336 337 // Find URLs that are on their own line. 338 $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); 337 if ( preg_match( '#(^|\s|>)https?://#i', $content ) ) { 338 // Find URLs on their own line. 339 $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); 340 // Find URLs in their own paragraph. 341 $content = preg_replace_callback( '|(<p[^>]*>\s*)(https?://[^\s<]+)(\s*<\/p>)|i', array( $this, 'autoembed_callback' ), $content ); 342 } 339 343 340 344 // Put the line breaks back. 341 345 return str_replace( '<!-- wp-line-break -->', "\n", $content ); -
tests/phpunit/tests/media.php
158 158 $this->assertEquals( $content, $result ); 159 159 } 160 160 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 172 test', 173 'test 174 [embed] 175 test' 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 187 https://w.org 188 test</p>', 189 '<p>test 190 [embed] 191 test</p>' 192 ), 193 array( 194 '<p>https://w.org 195 </p>', 196 '<p>[embed] 197 </p>' 198 ), 199 200 // Should NOT embed 201 array( 202 'test https://w.org</p>' 203 ), 204 array( 205 '<span>https://w.org</a>' 206 ), 207 array( 208 '<a href=" https://w.org "> 209 https://w.org 210 </a>' 211 ) 212 ); 213 } 214 215 /** 216 * @dataProvider data_autoembed 217 */ 218 function test_autoembed( $content, $result = null ) { 219 $wp_embed = new Test_Autoembed; 220 221 $this->assertEquals( $wp_embed->autoembed( $content ), $result ? $result : $content ); 222 } 223 161 224 function test_wp_prepare_attachment_for_js() { 162 225 // Attachment without media 163 226 $id = wp_insert_attachment(array( … … 1612 1675 $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) ); 1613 1676 } 1614 1677 } 1678 1679 /** 1680 * Helper class for `test_autoembed`. 1681 */ 1682 class Test_Autoembed extends WP_Embed { 1683 public function shortcode( $attr, $url = '' ) { 1684 return '[embed]'; 1685 } 1686 }