json_splitter: Don't break when buffer contains leading whitespace.
Add error logging with detailed output for decode errors Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
dec2c83014
commit
6f4be1cffc
2 changed files with 28 additions and 1 deletions
|
|
@ -15,6 +15,10 @@ class TestJsonSplitter(object):
|
|||
data = '{"foo": "bar"}\n \n{"next": "obj"}'
|
||||
assert utils.json_splitter(data) == ({'foo': 'bar'}, '{"next": "obj"}')
|
||||
|
||||
def test_json_splitter_leading_whitespace(self):
|
||||
data = '\n \r{"foo": "bar"}\n\n {"next": "obj"}'
|
||||
assert utils.json_splitter(data) == ({'foo': 'bar'}, '{"next": "obj"}')
|
||||
|
||||
|
||||
class TestStreamAsText(object):
|
||||
|
||||
|
|
@ -43,3 +47,16 @@ class TestJsonStream(object):
|
|||
[1, 2, 3],
|
||||
[],
|
||||
]
|
||||
|
||||
def test_with_leading_whitespace(self):
|
||||
stream = [
|
||||
'\n \r\n {"one": "two"}{"x": 1}',
|
||||
' {"three": "four"}\t\t{"x": 2}'
|
||||
]
|
||||
output = list(utils.json_stream(stream))
|
||||
assert output == [
|
||||
{'one': 'two'},
|
||||
{'x': 1},
|
||||
{'three': 'four'},
|
||||
{'x': 2}
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue