From a960fb828d614c93916803b3b127675ecbb3d41f Mon Sep 17 00:00:00 2001 From: TheSecEng Date: Tue, 25 May 2021 16:50:36 -0700 Subject: [PATCH] fix: keep_arrays_single_line issue where it splits on `,` in the middle of a string --- PrettyJson.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/PrettyJson.py b/PrettyJson.py index c1a9d2c..5a018af 100644 --- a/PrettyJson.py +++ b/PrettyJson.py @@ -83,12 +83,13 @@ def json_dumps(obj, minified: bool = False) -> str: 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)