mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 02:17:37 -02:30
Regress trailing comma modification and enhance error message
This commit is contained in:
@@ -62,9 +62,4 @@ class JSONParser(parsers.JSONParser):
|
|||||||
raise ParseError(_('JSON parse error - not a JSON object'))
|
raise ParseError(_('JSON parse error - not a JSON object'))
|
||||||
return obj
|
return obj
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
try:
|
raise ParseError(_('JSON parse error - %s\nPossible cause: trailing comma.' % six.text_type(exc)))
|
||||||
# PyYAML can also parse JSON-style input string, and support more flexible
|
|
||||||
# input grammar like trailing commas.
|
|
||||||
return yaml.load(data, OrderedDictLoader)
|
|
||||||
except Exception:
|
|
||||||
raise ParseError(_('JSON parse error - %s') % six.text_type(exc))
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
import StringIO
|
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from awx.api.parsers import JSONParser
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('input_, output', [
|
|
||||||
('{"foo": "bar", "alice": "bob"}', OrderedDict([("foo", "bar"), ("alice", "bob")])),
|
|
||||||
('{"foo": "bar", "alice": "bob",\n }', OrderedDict([("foo", "bar"), ("alice", "bob")])),
|
|
||||||
('{"foo": ["alice", "bob"]}', {"foo": ["alice","bob"]}),
|
|
||||||
('{"foo": ["alice", "bob",\n ]}', {"foo": ["alice","bob"]}),
|
|
||||||
('{"foo": "\\"bar, \\n}"}', {"foo": "\"bar, \n}"}),
|
|
||||||
('{"foo": ["\\"alice,\\n ]", "bob"]}', {"foo": ["\"alice,\n ]","bob"]}),
|
|
||||||
])
|
|
||||||
def test_trailing_comma_support(input_, output):
|
|
||||||
input_buffer = StringIO.StringIO()
|
|
||||||
input_buffer.write(input_)
|
|
||||||
input_buffer.seek(0)
|
|
||||||
assert JSONParser().parse(input_buffer) == output
|
|
||||||
input_buffer.close()
|
|
||||||
|
|
||||||
|
|
||||||
def test_yaml_load_preserves_input_order():
|
|
||||||
input_ = '{"a": "b", "c": "d", "e": "f"}'
|
|
||||||
output = ('a', 'c', 'e')
|
|
||||||
input_buffer = StringIO.StringIO()
|
|
||||||
input_buffer.write(input_)
|
|
||||||
input_buffer.seek(0)
|
|
||||||
assert tuple(JSONParser().parse(input_buffer)) == output
|
|
||||||
Reference in New Issue
Block a user