Permalink
Browse files

Merge pull request #911 from akirk/fix/android-escaped-unicode

Android Strings: Convert escaped unicode before stripping the slashes
  • Loading branch information...
toolstack committed Oct 18, 2018
2 parents 09d219e + a6f80bc commit 0de4570063cba85049bdce214ae7e7ff93a2193e
@@ -405,6 +405,19 @@ private function cmp_context( $a, $b ) {
return strnatcmp( $a->context, $b->context );
}
/**
* Preserve a Unicode sequence (like \u1234) by adding another backslash.
*
* @since 3.0
*
* @param string $string The string to process.
*
* @return string Returns the string with double-escaped Unicode sequences.
*/
private function preserve_escaped_unicode( $string ) {
return preg_replace( '#\\\\u([0-9a-fA-F]{4})#', '\\\\$0', $string );
}
/**
* Unescapes a string with c style slashes.
*
@@ -415,6 +428,7 @@ private function cmp_context( $a, $b ) {
* @return string Returns the unescaped string.
*/
private function unescape( $string ) {
$string = $this->preserve_escaped_unicode( $string );
return stripcslashes( $string );
}
@@ -9,4 +9,5 @@
<string name="with_gt">me > you</string>
<string name="with_amps">me &amp; you are not &amp;amp;</string>
<string name="with_comment" comment="Me, myself &amp; Irene">baba</string>
<string name="with_escaped_unicode">No posts saved \u2014 yet!</string>
</resources>
@@ -15,4 +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 \u2014 noch!</string>
</resources>
@@ -14,6 +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 \u2014 yet!', 'Keine Beiträge gespeichert \u2014 noch!', '' ),
);
}

0 comments on commit 0de4570

Please sign in to comment.