[Checkins] SVN: z3c.pt/trunk/ Fixed interpolation bug where multiple attributes with interpolation

Malthe Borch mborch at gmail.com
Tue Sep 2 06:43:41 EDT 2008


Log message for revision 90688:
  Fixed interpolation bug where multiple attributes with interpolation
    expressions would result in corrupted output.

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/src/z3c/pt/expressions.py

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-09-02 10:12:30 UTC (rev 90687)
+++ z3c.pt/trunk/CHANGES.txt	2008-09-02 10:43:41 UTC (rev 90688)
@@ -141,6 +141,9 @@
 
   Bugfixes
 
+- Fixed interpolation bug where multiple attributes with interpolation
+  expressions would result in corrupted output. [malthe]
+
 - Support try-except operator ('|') when 'python' is the default
   expression type. [malthe]
   

Modified: z3c.pt/trunk/src/z3c/pt/expressions.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/expressions.py	2008-09-02 10:12:30 UTC (rev 90687)
+++ z3c.pt/trunk/src/z3c/pt/expressions.py	2008-09-02 10:43:41 UTC (rev 90688)
@@ -446,19 +446,20 @@
         variable = m.group('variable')
         
         if expression:
-            left = m.start()+len(m.group('prefix'))
-            match = string[left+1:]
+            left = m.start()+len(m.group('prefix'))+1
+            right = string.find('}')
 
-            while match:
+            while right != -1:
+                match = string[left:right]
                 try:
                     exp = self.expression(match)
                     break
                 except SyntaxError:
-                    match = match[:-1]
+                    right = string.find('}', right)
             else:
                 raise
 
-            string = string[:left+1+len(match)]+'}'
+            string = string[:right+1]
             return self.re_interpolation.search(string)
 
         if m is None or (expression is None and variable is None):
@@ -604,10 +605,31 @@
         return super(StringTranslation, self).definitions(string)
 
     def _unescape(self, string):
+        """
+        >>> unescape = StringTranslation(python_translation)._unescape
+        
+        >>> unescape('string:Hello World')
+        'string:Hello World'
+        
+        >>> unescape('; string:Hello World')
+        Traceback (most recent call last):
+         ...
+        SyntaxError: Semi-colons in string-expressions must be escaped.
+
+        >>> unescape(';; string:Hello World')
+        '; string:Hello World'
+        
+        """
+        
         i = string.rfind(';')
-        if i > 0 and i != string.rfind(';'+';') + 1:
+        if i < 0:
+            return string
+        
+        j = string.rfind(';'+';')
+        if j < 0 or i != j + 1:
             raise SyntaxError(
                 "Semi-colons in string-expressions must be escaped.")
+        
         return string.replace(';;', ';')
 
 class PathTranslation(ExpressionTranslation):



More information about the Checkins mailing list