Skip to content

Commit 65bace0

Browse files
authored
Merge pull request #37 from fulder/master
Improve if condition for required last semi colon
2 parents cb02c5f + 4f57e06 commit 65bace0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

nginx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def loads(data, conf=True):
516516
index += m.end()
517517
continue
518518

519-
if ";" not in data[index:] and index+1 != len(data):
519+
if ";" not in data[index:] and "}" in data[index:]:
520520
# If there is still something to parse, expect ';' otherwise
521521
# the Key regexp can get stuck due to regexp catastrophic backtracking
522522
raise ParseError("Config syntax, missing ';' at index: {}".format(index))

tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@
213213
}
214214
"""
215215

216+
TESTBLOCK_CASE_13 = """
217+
server{
218+
}"""
219+
216220

217221
class TestPythonNginx(unittest.TestCase):
218222
def test_basic_load(self):
@@ -332,12 +336,15 @@ def test_missing_semi_colon(self):
332336
with pytest.raises(nginx.ParseError) as e:
333337
nginx.loads(TESTBLOCK_CASE_11)
334338
self.assertEqual(str(e.value), "Config syntax, missing ';' at index: 189")
335-
339+
336340
def test_brace_inside_block_param(self):
337341
inp_data = nginx.loads(TESTBLOCK_CASE_12)
338342
self.assertEqual(len(inp_data.server.filter("Location")), 1)
339343
self.assertEqual(inp_data.server.filter("Location")[0].value, "~ \"^/(test|[0-9a-zA-Z]{6})$\"")
340344

345+
def test_server_without_last_linebreak(self):
346+
self.assertTrue(nginx.loads(TESTBLOCK_CASE_13) is not None)
347+
341348

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

0 commit comments

Comments
 (0)