Merge "Fix str_split function when string is None"

This commit is contained in:
Jenkins 2016-08-02 11:50:26 +00:00 committed by Gerrit Code Review
commit 36dd261a97
2 changed files with 14 additions and 0 deletions

View File

@ -765,6 +765,10 @@ class StrSplit(function.Function):
except (AttributeError, IndexError):
raise ValueError(_('Incorrect arguments to "%(fn_name)s" '
'should be: %(example)s') % self.fmt_data)
if str_to_split is None:
return None
split_list = str_to_split.split(delim)
# Optionally allow an index to be specified

View File

@ -1291,6 +1291,16 @@ class HOTemplateTest(common.HeatTestCase):
self.assertIn('Incorrect arguments to \"str_split\"',
six.text_type(exc))
def test_str_split_none_string_to_split(self):
tmpl = template.Template(hot_liberty_tpl_empty)
snippet = {'str_split': ['.', None]}
self.assertIsNone(self.resolve(snippet, tmpl))
def test_str_split_none_delim(self):
tmpl = template.Template(hot_liberty_tpl_empty)
snippet = {'str_split': [None, 'check']}
self.assertEqual(['check'], self.resolve(snippet, tmpl))
def test_prevent_parameters_access(self):
"""Check parameters section inaccessible using the template as a dict.