Browse Source

Merge "Enforces unicode decoding of data"

changes/14/680114/1
Zuul 2 years ago
committed by Gerrit Code Review
parent
commit
de7f249adb
  1. 18
      heat_dashboard/content/stacks/forms.py
  2. 4
      heat_dashboard/test/tests/content/test_stacks.py

18
heat_dashboard/content/stacks/forms.py

@ -203,16 +203,16 @@ class TemplateForm(forms.SelfHandlingForm):
log_template_name = files[upload_str].name
LOG.info('got upload %s', log_template_name)
tpl = files[upload_str].read()
if tpl.startswith('{'):
try:
try:
tpl = files[upload_str].read().decode('utf-8')
if tpl.startswith('{'):
json.loads(tpl)
except Exception as e:
msg = _('There was a problem parsing the'
' %(prefix)s: %(error)s')
msg = msg % {'prefix': prefix, 'error': six.text_type(e)}
raise forms.ValidationError(msg)
cleaned[data_str] = tpl
cleaned[data_str] = tpl
except Exception as e:
msg = _('There was a problem parsing the'
' %(prefix)s: %(error)s')
msg = msg % {'prefix': prefix, 'error': six.text_type(e)}
raise forms.ValidationError(msg)
# URL handler
elif url and (has_upload or data):

4
heat_dashboard/test/tests/content/test_stacks.py

@ -918,7 +918,7 @@ class TemplateFormTests(test.TestCase):
}
json_str = '{notvalidjson::::::json/////json'
files = {'template_upload':
self.SimpleFile('template_name', json_str)}
self.SimpleFile('template_name', json_str.encode('utf-8'))}
self.assertRaises(
exceptions.ValidationError,
@ -937,7 +937,7 @@ class TemplateFormTests(test.TestCase):
json_str = '{"isvalid":"json"}'
files = {'template_upload':
self.SimpleFile('template_name', json_str)}
self.SimpleFile('template_name', json_str.encode('utf-8'))}
t.clean_uploaded_files('template', 'template', precleaned, files)
self.assertEqual(

Loading…
Cancel
Save