Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def loads(data, conf=True):
index += m.end()
continue

if ";" not in data[index:] and index+1 != len(data):
if ";" not in data[index:] and "}" in data[index:]:
# If there is still something to parse, expect ';' otherwise
# the Key regexp can get stuck due to regexp catastrophic backtracking
raise ParseError("Config syntax, missing ';' at index: {}".format(index))
Expand Down
9 changes: 8 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@
}
"""

TESTBLOCK_CASE_13 = """
server{
}"""


class TestPythonNginx(unittest.TestCase):
def test_basic_load(self):
Expand Down Expand Up @@ -332,12 +336,15 @@ def test_missing_semi_colon(self):
with pytest.raises(nginx.ParseError) as e:
nginx.loads(TESTBLOCK_CASE_11)
self.assertEqual(str(e.value), "Config syntax, missing ';' at index: 189")

def test_brace_inside_block_param(self):
inp_data = nginx.loads(TESTBLOCK_CASE_12)
self.assertEqual(len(inp_data.server.filter("Location")), 1)
self.assertEqual(inp_data.server.filter("Location")[0].value, "~ \"^/(test|[0-9a-zA-Z]{6})$\"")

def test_server_without_last_linebreak(self):
self.assertTrue(nginx.loads(TESTBLOCK_CASE_13) is not None)


if __name__ == '__main__':
unittest.main()