Ticket #36525: 36525.2.diff
| File 36525.2.diff, 6.0 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/formatting.php
diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php index ff0b6a4..bd7f141 100644
img.emoji { 4513 4513 } 4514 4514 4515 4515 /** 4516 * Print the inline Emoji detection script if it is not already printed. 4516 4517 * 4517 * @ global string $wp_version4518 * @since 4.2.0 4518 4519 * @staticvar bool $printed 4519 4520 */ 4520 4521 function print_emoji_detection_script() { 4521 global $wp_version;4522 4522 static $printed = false; 4523 4523 4524 4524 if ( $printed ) { … … function print_emoji_detection_script() { 4527 4527 4528 4528 $printed = true; 4529 4529 4530 _print_emoji_detection_script(); 4531 } 4532 4533 /** 4534 * Print inline Emoji dection script 4535 * 4536 * @ignore 4537 * @since 4.6.0 4538 * @access private 4539 * 4540 * @global string $wp_version 4541 */ 4542 function _print_emoji_detection_script() { 4543 global $wp_version; 4544 4530 4545 $settings = array( 4531 4546 /** 4532 * Filter the URL where emoji images are hosted.4547 * Filter the URL where emoji png images are hosted. 4533 4548 * 4534 4549 * @since 4.2.0 4535 4550 * 4536 * @param string The emoji base URL .4551 * @param string The emoji base URL for png images. 4537 4552 */ 4538 4553 'baseUrl' => apply_filters( 'emoji_url', 'https://s.w.org/images/core/emoji/72x72/' ), 4539 4554 4540 4555 /** 4541 * Filter the extension of the emoji files.4556 * Filter the extension of the emoji png files. 4542 4557 * 4543 4558 * @since 4.2.0 4544 4559 * 4545 * @param string The emoji extension . Default .png.4560 * @param string The emoji extension for png files. Default .png. 4546 4561 */ 4547 4562 'ext' => apply_filters( 'emoji_ext', '.png' ), 4563 4564 /** 4565 * Filter the URL where emoji SVG images are hosted. 4566 * 4567 * @since 4.2.0 4568 * 4569 * @param string The emoji base URL for svg images. 4570 */ 4571 'svgUrl' => apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/svg/' ), 4572 4573 /** 4574 * Filter the extension of the emoji SVG files. 4575 * 4576 * @since 4.2.0 4577 * 4578 * @param string The emoji extension for svg files. Default .svg. 4579 */ 4580 'svgExt' => apply_filters( 'emoji_svg_ext', '.svg' ), 4548 4581 ); 4549 4582 4550 4583 $version = 'ver=' . $wp_version; -
src/wp-includes/js/wp-emoji.js
diff --git src/wp-includes/js/wp-emoji.js src/wp-includes/js/wp-emoji.js index dafcc36..4156f01 100644
3 3 function wpEmoji() { 4 4 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, 5 5 6 // Compression and maintain local scope 7 document = window.document, 8 6 9 // Private 7 10 twemoji, timer, 8 11 loaded = false, … … 10 13 ie11 = window.navigator.userAgent.indexOf( 'Trident/7.0' ) > 0; 11 14 12 15 /** 16 * Detect if the browser supports SVG. 17 * 18 * @since 4.6.0 19 * 20 * @return {Boolean} True if the browser supports svg, false if not. 21 */ 22 function browserSupportsSvgAsImage() { 23 if ( !! document.implementation.hasFeature ) { 24 // Source: Modernizr 25 // https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg/asimg.js 26 return document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ); 27 } 28 29 // document.implementation.hasFeature is deprecated. It can be presumed 30 // if future browsers remove it, the browser will support SVGs as images. 31 return true; 32 } 33 34 /** 13 35 * Runs when the document load event is fired, so we can do our first parse of the page. 14 36 * 15 37 * @since 4.2.0 … … 141 163 142 164 args = args || {}; 143 165 params = { 144 base: settings.baseUrl,145 ext: settings.ext,166 base: browserSupportsSvgAsImage() ? settings.svgUrl : settings.baseUrl, 167 ext: browserSupportsSvgAsImage() ? settings.svgExt : settings.ext, 146 168 className: args.className || 'emoji', 147 169 callback: function( icon, options ) { 148 170 // Ignore some standard characters that TinyMCE recommends in its character map. -
new file tests/phpunit/tests/formatting/Emoji.php
diff --git tests/phpunit/tests/formatting/Emoji.php tests/phpunit/tests/formatting/Emoji.php new file mode 100644 index 0000000..6045747
- + 1 <?php 2 3 /** 4 * @group formatting 5 */ 6 class Tests_Formatting_Emoji extends WP_UnitTestCase { 7 /** 8 * @ticket 36525 9 */ 10 public function test_unfiltered_emoji_cdns() { 11 $png_cdn = 'https://s.w.org/images/core/emoji/72x72/'; 12 $svn_cdn = 'https://s.w.org/images/core/emoji/svg/'; 13 14 $output = get_echo( '_print_emoji_detection_script' ); 15 16 $this->assertContains( wp_json_encode( $png_cdn ), $output ); 17 $this->assertContains( wp_json_encode( $svn_cdn ), $output ); 18 } 19 20 public function _filtered_emoji_svn_cdn( $cdn = '' ) { 21 return 'https://s.wordpress.org/images/core/emoji/svg/'; 22 } 23 24 /** 25 * @ticket 36525 26 */ 27 public function test_filtered_emoji_svn_cdn() { 28 $png_cdn = 'https://s.w.org/images/core/emoji/72x72/'; 29 $svn_cdn = 'https://s.w.org/images/core/emoji/svg/'; 30 31 $filtered_svn_cdn = $this->_filtered_emoji_svn_cdn(); 32 33 add_filter( 'emoji_svg_url', array( $this, '_filtered_emoji_svn_cdn' ) ); 34 35 $output = get_echo( '_print_emoji_detection_script' ); 36 37 $this->assertContains( wp_json_encode( $png_cdn ), $output ); 38 $this->assertNotContains( wp_json_encode( $svn_cdn ), $output ); 39 $this->assertContains( wp_json_encode( $filtered_svn_cdn ), $output ); 40 41 remove_filter( 'emoji_svg_url', array( $this, '_filtered_emoji_svn_cdn' ) ); 42 } 43 44 public function _filtered_emoji_png_cdn( $cdn = '' ) { 45 return 'https://s.wordpress.org/images/core/emoji/png_cdn/'; 46 } 47 48 /** 49 * @ticket 36525 50 */ 51 public function test_filtered_emoji_png_cdn() { 52 $png_cdn = 'https://s.w.org/images/core/emoji/72x72/'; 53 $svn_cdn = 'https://s.w.org/images/core/emoji/svg/'; 54 55 $filtered_png_cdn = $this->_filtered_emoji_png_cdn(); 56 57 add_filter( 'emoji_url', array( $this, '_filtered_emoji_png_cdn' ) ); 58 59 $output = get_echo( '_print_emoji_detection_script' ); 60 61 $this->assertContains( wp_json_encode( $filtered_png_cdn ), $output ); 62 $this->assertNotContains( wp_json_encode( $png_cdn ), $output ); 63 $this->assertContains( wp_json_encode( $svn_cdn ), $output ); 64 65 remove_filter( 'emoji_url', array( $this, '_filtered_emoji_png_cdn' ) ); 66 } 67 68 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)