Commits

Ratnadeep Debnath committed c02cd4a

Escape/unescape new lines correctly in Joomla INI files.

  • Participants
  • Parent commits be08dfb

Comments (0)

Files changed (2)

File transifex/resources/formats/joomla.py

     HandlerCompileError = JoomlaCompileError
 
     def _escape(self, s):
-        return s.replace('\\', '\\\\')
+        return  s.replace('\\', '\\\\').replace('\n', r'\\n').replace('\r', r'\\r')
+
+    def _unescape(self, s):
+        return s.replace('\\n', '\n').replace('\\r', '\r')
 
     def _examine_content(self, content):
         self.jformat = JoomlaIniVersion.create(content)
             elif not SourceEntity.objects.filter(resource=self.resource, string=source).exists() or not trans.strip():
                 #ignore keys with no translation
                 continue
-            self._add_translation_string(source, trans, context=context)
+            self._add_translation_string(source, self._unescape(trans),
+                    context=context)
         return buf[:buf.rfind(self.linesep)]
 
 

File transifex/resources/tests/lib/joomla_ini/__init__.py

         self.assertEqual(translation_strings, ['Translation with "quotes"',
                 'Translation with a quote "'])
 
+        """Test unescaping of new lines during parsing"""
+        content = 'KEY1=Translation\\nwith new line \\r\\n'
+        self.parser.bind_content(content)
+        self.parser.parse_file(is_source=True)
+        translation_string = self.parser.stringset.strings[0].translation
+        self.assertEqual(translation_string, 'Translation\nwith new line \r\n')
 
+