[schema] improve normalization of RQLExpressions
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 08 Sep 2015 16:26:56 +0200
changeset 10653 42c5bd7286b7
parent 10652 e3e4a8c45695
child 10654 d6d9913753d2
[schema] improve normalization of RQLExpressions Parse and print back the expression instead of manipulating the string. Among other benefits, it means we don't mangle embedded string constants that contain commas or multiple spaces. Closes #6694426
schema.py
test/unittest_schema.py
--- a/schema.py	Tue Sep 08 13:43:57 2015 +0200
+++ b/schema.py	Tue Sep 08 16:26:56 2015 +0200
@@ -146,7 +146,10 @@
     suppressing and reinserting an expression if only a space has been
     added/removed for instance)
     """
-    return u', '.join(' '.join(expr.split()) for expr in rqlstring.split(','))
+    union = parse(u'Any 1 WHERE %s' % rqlstring).as_string()
+    if isinstance(union, str):
+        union = union.decode('utf-8')
+    return union.split(' WHERE ', 1)[1]
 
 
 def _check_valid_formula(rdef, formula_rqlst):
--- a/test/unittest_schema.py	Tue Sep 08 13:43:57 2015 +0200
+++ b/test/unittest_schema.py	Tue Sep 08 16:26:56 2015 +0200
@@ -426,7 +426,9 @@
 
     def test(self):
         self.assertEqual(normalize_expression('X  bla Y,Y blur Z  ,  Z zigoulou   X '),
-                                               'X bla Y, Y blur Z, Z zigoulou X')
+                                              'X bla Y, Y blur Z, Z zigoulou X')
+        self.assertEqual(normalize_expression('X bla Y, Y name "x,y"'),
+                                              'X bla Y, Y name "x,y"')
 
 
 class RQLExpressionTC(TestCase):