r54126 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54125‎ | r54126 | r54127 >
Date:21:47, 31 July 2009
Author:roberthl
Status:ok
Tags:
Comment:
Translate:
* Add function to OpenLayers FFS for unescaping escaped JS strings, needs implementing in new FFS system.
Modified paths:
  • /trunk/extensions/Translate/ffs/OpenLayers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/ffs/OpenLayers.php
@@ -10,6 +10,33 @@
1111
1212 class OpenLayersFormatReader extends SimpleFormatReader {
1313
 14+ private static function unescapeJsString( $string ) {
 15+ // See ECMA 262 section 7.8.4 for string literal format
 16+ $pairs = array(
 17+ "\\" => "\\\\",
 18+ "\"" => "\\\"",
 19+ '\'' => '\\\'',
 20+ "\n" => "\\n",
 21+ "\r" => "\\r",
 22+
 23+ # To avoid closing the element or CDATA section
 24+ "<" => "\\x3c",
 25+ ">" => "\\x3e",
 26+
 27+ # To avoid any complaints about bad entity refs
 28+ "&" => "\\x26",
 29+
 30+ # Work around https://bugzilla.mozilla.org/show_bug.cgi?id=274152
 31+ # Encode certain Unicode formatting chars so affected
 32+ # versions of Gecko don't misinterpret our strings;
 33+ # this is a common problem with Farsi text.
 34+ "\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER
 35+ "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER
 36+ );
 37+ $pairs = array_flip( $pairs );
 38+ return strtr( $string, $pairs );
 39+ }
 40+
1441 private function leftTrim( $string ) {
1542 $string = ltrim( $string );
1643 $string = ltrim( $string, '"' );
@@ -61,7 +88,7 @@
6289 // Remove quotation marks and syntax.
6390 $key = substr( $key, 1 );
6491 $value = substr( $value, 1, -1 );
65 - $messages[ $key ] = $value;
 92+ $messages[ $key ] = self::unescapeJsString( $value );
6693 }
6794
6895 // Remove extraneous key that is sometimes present.

Status & tagging log