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