Merge pull request #6 from RickieL/master

Fix rewrite regex number choice "curly bracket" case.
pull/12/head
Michał Słomkowski 6 years ago committed by GitHub
commit 6df60552dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -67,9 +67,15 @@ def clean_lines(orig_lines) -> list:
if line.startswith("#"):
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

@ -37,6 +37,12 @@ class TestFormatter(unittest.TestCase):
self.assertEqual(["{", "ala", "# ma {{", "kota", "}", "to", "}", "# }"],
clean_lines(("{", "ala ", "# ma {{", " kota ", "}", " to} ", "# }")))
self.assertEqual(["{", "ala", "# ma {{", "rewrite /([\d]{2}) /up/$1.html last;", "}", "to", "}"],
clean_lines(("{", "ala ", "# ma {{", " rewrite /([\d]{2}) /up/$1.html last; ", "}", " to", "}")))
self.assertEqual(["{", "ala", "# ma {{", "aa last;", "bb to;", "}"],
clean_lines(("{", "ala ", "# ma {{", " aa last; bb to; ", "}")))
self.assertEqual(["location ~ /\.ht", "{"], clean_lines(["location ~ /\.ht {", ]))
def test_perform_indentation(self):
@ -178,6 +184,16 @@ class TestFormatter(unittest.TestCase):
'}\n' +
'# in my line\n')
def test_multi_semicolon(self):
self._check_formatting('location /a { \n' +
'allow 127.0.0.1; allow 10.0.0.0/8; deny all; \n' +
'}\n',
'location /a {\n' +
' allow 127.0.0.1;\n' +
' allow 10.0.0.0/8;\n' +
' deny all;\n' +
'}\n')
def test_loading_utf8_file(self):
tmp_file = tempfile.mkstemp('utf-8')[1]
shutil.copy('test-files/umlaut-utf8.conf', tmp_file)

Loading…
Cancel
Save