Merge "Safely encode yaql expressions to support unicode expressions"
This commit is contained in:
commit
521039d511
@ -15,6 +15,8 @@
|
|||||||
import re
|
import re
|
||||||
import types
|
import types
|
||||||
|
|
||||||
|
from oslo_utils import encodeutils
|
||||||
|
|
||||||
import yaql
|
import yaql
|
||||||
import yaql.exceptions
|
import yaql.exceptions
|
||||||
import yaql.expressions
|
import yaql.expressions
|
||||||
@ -23,7 +25,7 @@ import yaql.expressions
|
|||||||
class YaqlExpression(object):
|
class YaqlExpression(object):
|
||||||
def __init__(self, expression):
|
def __init__(self, expression):
|
||||||
if isinstance(expression, types.StringTypes):
|
if isinstance(expression, types.StringTypes):
|
||||||
self._expression = str(expression)
|
self._expression = encodeutils.safe_encode(expression)
|
||||||
self._parsed_expression = yaql.parse(self._expression)
|
self._parsed_expression = yaql.parse(self._expression)
|
||||||
self._file_position = None
|
self._file_position = None
|
||||||
elif isinstance(expression, YaqlExpression):
|
elif isinstance(expression, YaqlExpression):
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# coding: utf-8
|
||||||
# Copyright (c) 2014 Mirantis Inc.
|
# Copyright (c) 2014 Mirantis Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -164,6 +165,19 @@ class TestYaqlExpression(base.MuranoTestCase):
|
|||||||
|
|
||||||
self.assertEqual('string', yaql_expr.expression)
|
self.assertEqual('string', yaql_expr.expression)
|
||||||
|
|
||||||
|
def test_unicode_expression(self):
|
||||||
|
yaql_expr = yaql_expression.YaqlExpression(u"'yaql ♥ unicode'")
|
||||||
|
|
||||||
|
self.assertEqual(u"'yaql ♥ unicode'".encode('utf-8'),
|
||||||
|
yaql_expr.expression)
|
||||||
|
|
||||||
|
def test_unicode_expression_expression(self):
|
||||||
|
yaql_expr = yaql_expression.YaqlExpression(u"'yaql ♥ unicode'")
|
||||||
|
yaql_expr2 = yaql_expression.YaqlExpression(yaql_expr)
|
||||||
|
|
||||||
|
self.assertEqual(u"'yaql ♥ unicode'".encode('utf-8'),
|
||||||
|
yaql_expr2.expression)
|
||||||
|
|
||||||
def test_evaluate_calls(self):
|
def test_evaluate_calls(self):
|
||||||
string = 'string'
|
string = 'string'
|
||||||
expected_calls = [mock.call(string),
|
expected_calls = [mock.call(string),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user