Emoji: Work around a `mod_security` rule which prevents pages with 4 or more instances of `String.fromCharCode(` from being served.

Fixes #35412 for trunk.

Built from https://develop.svn.wordpress.org/trunk@36359


git-svn-id: http://core.svn.wordpress.org/trunk@36326 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2016-01-20 07:40:28 +00:00
parent 6c3261d3da
commit dddfbfa1d3
4 changed files with 9 additions and 8 deletions

View File

@ -4579,7 +4579,7 @@ function print_emoji_detection_script() {
?> ?>
<script type="text/javascript"> <script type="text/javascript">
window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>; window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>;
!function(a,b,c){function d(a){var c,d=b.createElement("canvas"),e=d.getContext&&d.getContext("2d");return e&&e.fillText?(e.textBaseline="top",e.font="600 32px Arial","flag"===a?(e.fillText(String.fromCharCode(55356,56806,55356,56826),0,0),d.toDataURL().length>3e3):"diversity"===a?(e.fillText(String.fromCharCode(55356,57221),0,0),c=e.getImageData(16,16,1,1).data.toString(),e.fillText(String.fromCharCode(55356,57221,55356,57343),0,0),c!==e.getImageData(16,16,1,1).data.toString()):("simple"===a?e.fillText(String.fromCharCode(55357,56835),0,0):e.fillText(String.fromCharCode(55356,57135),0,0),0!==e.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag"),unicode8:d("unicode8"),diversity:d("diversity")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag&&c.supports.unicode8&&c.supports.diversity||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings); !function(a,b,c){function d(a){var c,d=b.createElement("canvas"),e=d.getContext&&d.getContext("2d"),f=String.fromCharCode;return e&&e.fillText?(e.textBaseline="top",e.font="600 32px Arial","flag"===a?(e.fillText(f(55356,56806,55356,56826),0,0),d.toDataURL().length>3e3):"diversity"===a?(e.fillText(f(55356,57221),0,0),c=e.getImageData(16,16,1,1).data.toString(),e.fillText(f(55356,57221,55356,57343),0,0),c!==e.getImageData(16,16,1,1).data.toString()):("simple"===a?e.fillText(f(55357,56835),0,0):e.fillText(f(55356,57135),0,0),0!==e.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag"),unicode8:d("unicode8"),diversity:d("diversity")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag&&c.supports.unicode8&&c.supports.diversity||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);
</script> </script>
<?php <?php
} }

View File

@ -13,6 +13,7 @@
function browserSupportsEmoji( type ) { function browserSupportsEmoji( type ) {
var canvas = document.createElement( 'canvas' ), var canvas = document.createElement( 'canvas' ),
context = canvas.getContext && canvas.getContext( '2d' ), context = canvas.getContext && canvas.getContext( '2d' ),
stringFromCharCode = String.fromCharCode,
tone; tone;
if ( ! context || ! context.fillText ) { if ( ! context || ! context.fillText ) {
@ -37,7 +38,7 @@
* The first two will encode to small images (1-2KB data URLs), the third will encode * The first two will encode to small images (1-2KB data URLs), the third will encode
* to a larger image (4-5KB data URL). * to a larger image (4-5KB data URL).
*/ */
context.fillText( String.fromCharCode( 55356, 56806, 55356, 56826 ), 0, 0 ); context.fillText( stringFromCharCode( 55356, 56806, 55356, 56826 ), 0, 0 );
return canvas.toDataURL().length > 3000; return canvas.toDataURL().length > 3000;
} else if ( 'diversity' === type ) { } else if ( 'diversity' === type ) {
/* /*
@ -45,9 +46,9 @@
* emoji with no skin tone specified (in this case, Santa). It then adds a skin tone, and * emoji with no skin tone specified (in this case, Santa). It then adds a skin tone, and
* compares if the emoji rendering has changed. * compares if the emoji rendering has changed.
*/ */
context.fillText( String.fromCharCode( 55356, 57221 ), 0, 0 ); context.fillText( stringFromCharCode( 55356, 57221 ), 0, 0 );
tone = context.getImageData( 16, 16, 1, 1 ).data.toString(); tone = context.getImageData( 16, 16, 1, 1 ).data.toString();
context.fillText( String.fromCharCode( 55356, 57221, 55356, 57343 ), 0, 0 ); context.fillText( stringFromCharCode( 55356, 57221, 55356, 57343 ), 0, 0 );
// Chrome has issues comparing arrays, so we compare it as a string, instead. // Chrome has issues comparing arrays, so we compare it as a string, instead.
return tone !== context.getImageData( 16, 16, 1, 1 ).data.toString(); return tone !== context.getImageData( 16, 16, 1, 1 ).data.toString();
} else { } else {
@ -57,13 +58,13 @@
* center pixel. In browsers that don't support emoji, the character will be rendered * center pixel. In browsers that don't support emoji, the character will be rendered
* as an empty square, so the center pixel will be blank. * as an empty square, so the center pixel will be blank.
*/ */
context.fillText( String.fromCharCode( 55357, 56835 ), 0, 0 ); context.fillText( stringFromCharCode( 55357, 56835 ), 0, 0 );
} else { } else {
/* /*
* To check for Unicode 8 support, let's try rendering the most important advancement * To check for Unicode 8 support, let's try rendering the most important advancement
* that the Unicode Consortium have made in years: the burrito. * that the Unicode Consortium have made in years: the burrito.
*/ */
context.fillText( String.fromCharCode( 55356, 57135 ), 0, 0 ); context.fillText( stringFromCharCode( 55356, 57135 ), 0, 0 );
} }
return context.getImageData( 16, 16, 1, 1 ).data[0] !== 0; return context.getImageData( 16, 16, 1, 1 ).data[0] !== 0;
} }

View File

@ -1 +1 @@
!function(a,b,c){function d(a){var c,d=b.createElement("canvas"),e=d.getContext&&d.getContext("2d");return e&&e.fillText?(e.textBaseline="top",e.font="600 32px Arial","flag"===a?(e.fillText(String.fromCharCode(55356,56806,55356,56826),0,0),d.toDataURL().length>3e3):"diversity"===a?(e.fillText(String.fromCharCode(55356,57221),0,0),c=e.getImageData(16,16,1,1).data.toString(),e.fillText(String.fromCharCode(55356,57221,55356,57343),0,0),c!==e.getImageData(16,16,1,1).data.toString()):("simple"===a?e.fillText(String.fromCharCode(55357,56835),0,0):e.fillText(String.fromCharCode(55356,57135),0,0),0!==e.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag"),unicode8:d("unicode8"),diversity:d("diversity")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag&&c.supports.unicode8&&c.supports.diversity||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings); !function(a,b,c){function d(a){var c,d=b.createElement("canvas"),e=d.getContext&&d.getContext("2d"),f=String.fromCharCode;return e&&e.fillText?(e.textBaseline="top",e.font="600 32px Arial","flag"===a?(e.fillText(f(55356,56806,55356,56826),0,0),d.toDataURL().length>3e3):"diversity"===a?(e.fillText(f(55356,57221),0,0),c=e.getImageData(16,16,1,1).data.toString(),e.fillText(f(55356,57221,55356,57343),0,0),c!==e.getImageData(16,16,1,1).data.toString()):("simple"===a?e.fillText(f(55357,56835),0,0):e.fillText(f(55356,57135),0,0),0!==e.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag"),unicode8:d("unicode8"),diversity:d("diversity")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag&&c.supports.unicode8&&c.supports.diversity||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.5-alpha-36352'; $wp_version = '4.5-alpha-36359';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.