fix: keep_arrays_single_line issue where it splits on `,` in the middle

of a string
This commit is contained in:
TheSecEng 2021-05-25 16:50:36 -07:00
parent 51859d62e8
commit a960fb828d
No known key found for this signature in database
GPG Key ID: 4D98046FE19FF417
1 changed files with 4 additions and 3 deletions

View File

@ -83,12 +83,13 @@ class PrettyJsonBaseCommand:
matches.sort(key=len, reverse=True)
join_separator = line_separator.ljust(2)
for m in matches:
content = m[1:-1]
items = [a.strip() for a in content.split(line_separator.strip())]
content = m[1:-1].strip()
items = [a.strip() for a in content.split(os.linesep)]
items = [item[:-1] if item[-1] == ',' else item for item in items]
replacement = f'[{join_separator.join(items)}]'
if len(replacement) <= s.get('max_arrays_line_length', 120):
output_json = output_json.replace(m, replacement, 1)
elif s.get('bracket_newline', True):
output_json = PrettyJsonBaseCommand.bracket_newline.sub(r'\1\n\2\3', output_json)