Fix handling of non-JSON lines in responses

Garbage lines with ' = ' in them were causing parsing errors,
where key=val lines should not have spaces around the equals.

Fixes #6962
This commit is contained in:
James Cammarata 2014-04-17 13:18:57 -05:00
parent 09e0d1c51f
commit 5e598c5337

View file

@ -884,10 +884,11 @@ def filter_leading_non_json_lines(buf):
filter only leading lines since multiline JSON is valid. filter only leading lines since multiline JSON is valid.
''' '''
kv_regex = re.compile(r'.*\w+=\w+.*')
filtered_lines = StringIO.StringIO() filtered_lines = StringIO.StringIO()
stop_filtering = False stop_filtering = False
for line in buf.splitlines(): for line in buf.splitlines():
if stop_filtering or "=" in line or line.startswith('{') or line.startswith('['): if stop_filtering or kv_regex.match(line) or line.startswith('{') or line.startswith('['):
stop_filtering = True stop_filtering = True
filtered_lines.write(line + '\n') filtered_lines.write(line + '\n')
return filtered_lines.getvalue() return filtered_lines.getvalue()