From 30b136d485d06fd11693814eb8f20c352e06f2b1 Mon Sep 17 00:00:00 2001 From: fulder Date: Sat, 22 Aug 2020 14:35:42 +0200 Subject: [PATCH 1/2] Improve condition for checking of last missing semi colon --- nginx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.py b/nginx.py index 1cbb39d..75ed7e9 100755 --- a/nginx.py +++ b/nginx.py @@ -515,7 +515,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)) From 5dabc303c299eb61ef8741a97406e798bb6201a5 Mon Sep 17 00:00:00 2001 From: fulder Date: Sat, 22 Aug 2020 14:41:56 +0200 Subject: [PATCH 2/2] Add previously failing test for missing last line break --- tests.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests.py b/tests.py index e383a6e..debbd79 100755 --- a/tests.py +++ b/tests.py @@ -194,6 +194,10 @@ } """ +TESTBLOCK_CASE_12 = """ +server{ +}""" + class TestPythonNginx(unittest.TestCase): def test_basic_load(self): @@ -312,6 +316,9 @@ def test_missing_semi_colon(self): nginx.loads(TESTBLOCK_CASE_11) self.assertEqual(str(e.value), "Config syntax, missing ';' at index: 189") + def test_server_without_last_linebreak(self): + self.assertTrue(nginx.loads(TESTBLOCK_CASE_12) is not None) + if __name__ == '__main__': unittest.main()