Skip to content

Commit 8c10798

Browse files
committed
Add ParseError exception for missing semicolon
1 parent 4ecd1cd commit 8c10798

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

nginx.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
INDENT = ' '
1212

1313

14+
class Error(Exception):
15+
pass
16+
17+
18+
class ParseError(Error):
19+
pass
20+
21+
1422
def bump_child_depth(obj, depth):
1523
children = getattr(obj, 'children', [])
1624
for child in children:
@@ -67,7 +75,7 @@ def filter(self, btype='', name=''):
6775
for x in self.children:
6876
if name and isinstance(x, Key) and x.name == name:
6977
filtered.append(x)
70-
elif isinstance(x, Container) and x.__class__.__name__ == btype\
78+
elif isinstance(x, Container) and x.__class__.__name__ == btype \
7179
and x.value == name:
7280
filtered.append(x)
7381
elif not name and btype and x.__class__.__name__ == btype:
@@ -164,7 +172,7 @@ def filter(self, btype='', name=''):
164172
for x in self.children:
165173
if name and isinstance(x, Key) and x.name == name:
166174
filtered.append(x)
167-
elif isinstance(x, Container) and x.__class__.__name__ == btype\
175+
elif isinstance(x, Container) and x.__class__.__name__ == btype \
168176
and x.value == name:
169177
filtered.append(x)
170178
elif not name and btype and x.__class__.__name__ == btype:
@@ -507,6 +515,11 @@ def loads(data, conf=True):
507515
index += m.end()
508516
continue
509517

518+
if ";" not in data[index:] and index+1 != len(data):
519+
# If there is still something to parse, expect ';' otherwise
520+
# the Key regexp can get stuck due to regexp catastrophic backtracking
521+
raise ParseError(f"Config syntax, missing ';' at index: {index}")
522+
510523
double = r'\s*"[^"]*"'
511524
single = r'\s*\'[^\']*\''
512525
normal = r'\s*[^;\s]*'

0 commit comments

Comments
 (0)