From 93748ca7a8df3bb112e7ae8390b2be518fad4895 Mon Sep 17 00:00:00 2001 From: RickieL Date: Mon, 10 Sep 2018 23:28:22 +0800 Subject: [PATCH] fix multiline `;` in one line case and rewrite regex curly bracket case. fix multiline `;` in one line case and rewrite regex curly bracket case. --- nginxfmt.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nginxfmt.py b/nginxfmt.py index 418b348..3244b85 100755 --- a/nginxfmt.py +++ b/nginxfmt.py @@ -66,12 +66,16 @@ def clean_lines(orig_lines) -> list: else: if line.startswith("#"): cleaned_lines.append(strip_variable_template_tags(line)) - elif line.startswith("rewrite"): - cleaned_lines.append(strip_variable_template_tags(line)) else: - cleaned_lines.extend( - [strip_variable_template_tags(l).strip() for l in re.split(r"([{}])", line) if l != ""]) - + if line.count(";") > 1: + newlines = line.split(";") + cleaned_lines.extend(clean_lines(["".join([ln, ";"]) for ln in newlines if ln != ""])) + else: + if line.startswith("rewrite"): + cleaned_lines.append(strip_variable_template_tags(line)) + else: + cleaned_lines.extend( + [strip_variable_template_tags(l).strip() for l in re.split(r"([{}])", line) if l != ""]) return cleaned_lines