Merge "Enforces unicode decoding of data"
This commit is contained in:
commit
de7f249adb
@ -203,16 +203,16 @@ class TemplateForm(forms.SelfHandlingForm):
|
|||||||
log_template_name = files[upload_str].name
|
log_template_name = files[upload_str].name
|
||||||
LOG.info('got upload %s', log_template_name)
|
LOG.info('got upload %s', log_template_name)
|
||||||
|
|
||||||
tpl = files[upload_str].read()
|
try:
|
||||||
if tpl.startswith('{'):
|
tpl = files[upload_str].read().decode('utf-8')
|
||||||
try:
|
if tpl.startswith('{'):
|
||||||
json.loads(tpl)
|
json.loads(tpl)
|
||||||
except Exception as e:
|
cleaned[data_str] = tpl
|
||||||
msg = _('There was a problem parsing the'
|
except Exception as e:
|
||||||
' %(prefix)s: %(error)s')
|
msg = _('There was a problem parsing the'
|
||||||
msg = msg % {'prefix': prefix, 'error': six.text_type(e)}
|
' %(prefix)s: %(error)s')
|
||||||
raise forms.ValidationError(msg)
|
msg = msg % {'prefix': prefix, 'error': six.text_type(e)}
|
||||||
cleaned[data_str] = tpl
|
raise forms.ValidationError(msg)
|
||||||
|
|
||||||
# URL handler
|
# URL handler
|
||||||
elif url and (has_upload or data):
|
elif url and (has_upload or data):
|
||||||
|
@ -918,7 +918,7 @@ class TemplateFormTests(test.TestCase):
|
|||||||
}
|
}
|
||||||
json_str = '{notvalidjson::::::json/////json'
|
json_str = '{notvalidjson::::::json/////json'
|
||||||
files = {'template_upload':
|
files = {'template_upload':
|
||||||
self.SimpleFile('template_name', json_str)}
|
self.SimpleFile('template_name', json_str.encode('utf-8'))}
|
||||||
|
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exceptions.ValidationError,
|
exceptions.ValidationError,
|
||||||
@ -937,7 +937,7 @@ class TemplateFormTests(test.TestCase):
|
|||||||
|
|
||||||
json_str = '{"isvalid":"json"}'
|
json_str = '{"isvalid":"json"}'
|
||||||
files = {'template_upload':
|
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)
|
t.clean_uploaded_files('template', 'template', precleaned, files)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
Loading…
Reference in New Issue
Block a user