diff --git a/nginx.py b/nginx.py index 45a6b27..5bb1489 100755 --- a/nginx.py +++ b/nginx.py @@ -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)) diff --git a/tests.py b/tests.py index 6cabb7e..84c53a4 100755 --- a/tests.py +++ b/tests.py @@ -213,6 +213,10 @@ } """ +TESTBLOCK_CASE_13 = """ +server{ +}""" + class TestPythonNginx(unittest.TestCase): def test_basic_load(self): @@ -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()