Commits

Ratnadeep Debnath  committed cb626aa

Fixed escaping/unescaping rules in Mozilla properties handler
based on http://hg.mozilla.org/mozilla-central/file/0a5fdc470f9a/xpcom/ds/nsPersistentProperties.cpp#l229.

  • Participants
  • Parent commits 07490ca

Comments (0)

Files changed (4)

File transifex/resources/formats/mozillaproperties.py

     CompilerClass = PropertiesCompiler
 
     def _escape(self, s):
-        """
-        Escape special characters in Mozilla properties files.
+        return (s.replace('\\', r'\\')
+                 .replace('\n', r'\n')
+                 .replace('\r', r'\r')
+                 .replace('\t', r'\t')
+        )
 
-        Java escapes the '=' and ':' in the value
-        string with backslashes in the store method.
-        Mozilla escapes only '\\'.
-        """
-        return s.replace('\\', '\\\\')
+    def _unescape(self, s):
+        return (s.replace(r'\n', '\n')
+                 .replace(r'\r', '\r')
+                 .replace(r'\t', '\t')
+                 .replace(r'\\', '\\')
+        )
 
-    def _unescape(self, value):
-        """Reverse the escape of special characters."""
-        return value.replace('\\\\', '\\')
+    def _visit_value(self, value):
+        if value:
+            return re.sub(r'\\[uU]([0-9A-Fa-f]{4})',
+                    lambda m: unichr(int(m.group(1), 16)), value)
+        else:
+            return value

File transifex/resources/tests/lib/mozilla_properties/complex.properties

 # notKey02=notValue02 This is a comment and ignored.
 ! notKey03=notValue03 This is a comment and ignored.
 
-Key00:Value00
-Key01=Value01
+Key00:Value00\u4564def
+Key01=Value01\\\r\n\t
    Key02:Value02
    Key03       :     Value03
       Key04       =     Value04

File transifex/resources/tests/lib/mozilla_properties/complex_compiled.properties

 # notKey02=notValue02 This is a comment and ignored.
 ! notKey03=notValue03 This is a comment and ignored.
 
-Key00:Value00
-Key01=Value01
+Key00:Value00䕤def
+Key01=Value01\\\r\n\t
 Key02:Value02
 Key03       :     Value03
 Key04       =     Value04

File transifex/resources/tests/lib/mozilla_properties/complex_hi_IN_compiled_for_review.properties

 ! notKey03=notValue03 This is a comment and ignored.
 
 Key00:मूल्य00
-# Key01=Value01
+# Key01=Value01\\\r\n\t
 Key02:मूल्य02
 # Key03       :     Value03
 # Key04       =     Value04