# HG changeset patch # User Julien Cristau # Date 1441722416 -7200 # Node ID 42c5bd7286b7b10f59e155eebcfe4985d1aac821 # Parent e3e4a8c4569524b0e38d28924e8dc0f3891deb67 [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 diff -r e3e4a8c45695 -r 42c5bd7286b7 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): diff -r e3e4a8c45695 -r 42c5bd7286b7 test/unittest_schema.py --- 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):