Skip to content

Commit

Permalink
Double encode unicode backslash before stripcslashes
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Oct 17, 2018
1 parent 707a875 commit 8d8f3c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions gp-includes/formats/format-android.php
Expand Up @@ -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 );
}

/**
Expand All @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/data/translation.android.xml
Expand Up @@ -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>
Expand Up @@ -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!', '' ),
);
}

Expand Down

0 comments on commit 8d8f3c3

Please sign in to comment.