Permalink
Browse files

Double encode unicode backslash before stripcslashes

  • Loading branch information...
akirk committed Oct 17, 2018
1 parent 707a875 commit 8d8f3c3bb4f83afd56b4618bfadaafd889b60dd7
@@ -414,10 +414,8 @@ private function cmp_context( $a, $b ) {
*
* @return string Returns the unescaped string.
*/
private function unescape_unicode( $string ) {
return preg_replace_callback( '#\\\\u([0-9a-fA-F]{4})#', function ( $match ) {
return mb_convert_encoding( pack( 'H*', $match[1] ), 'UTF-8', 'UTF-16BE' );
}, $string );
private function preserve_escaped_unicode( $string ) {
return preg_replace( '#\\\\u([0-9a-fA-F]{4})#', '\\\\$0', $string );
}
/**
@@ -430,7 +428,7 @@ private function unescape_unicode( $string ) {
* @return string Returns the unescaped string.
*/
private function unescape( $string ) {
$string = $this->unescape_unicode( $string );
$string = $this->preserve_escaped_unicode( $string );
return stripcslashes( $string );
}
@@ -15,5 +15,5 @@ Language: en_US
<string name="with_gt">аз > ти</string>
<string name="with_amps">аз &amp; ти не сме &amp;amp;</string>
<string name="with_comment">баба</string>
<string name="with_escaped_unicode">Keine Beiträge gespeichert noch!</string>
<string name="with_escaped_unicode">Keine Beiträge gespeichert \u2014 noch!</string>
</resources>
@@ -14,7 +14,7 @@ function setUp() {
array( 'with_gt', 'me > you', "аз > ти", '' ),
array( 'with_amps', 'me & you are not &amp;', 'аз & ти не сме &amp;', '' ),
array( 'with_comment', 'baba', 'баба', 'Me, myself & Irene' ),
array( 'with_escaped_unicode', 'No posts saved yet!', 'Keine Beiträge gespeichert noch!', '' ),
array( 'with_escaped_unicode', 'No posts saved \u2014 yet!', 'Keine Beiträge gespeichert \u2014 noch!', '' ),
);
}

0 comments on commit 8d8f3c3

Please sign in to comment.