|
11 | 11 | INDENT = ' ' |
12 | 12 |
|
13 | 13 |
|
| 14 | +class Error(Exception): |
| 15 | + pass |
| 16 | + |
| 17 | + |
| 18 | +class ParseError(Error): |
| 19 | + pass |
| 20 | + |
| 21 | + |
14 | 22 | def bump_child_depth(obj, depth): |
15 | 23 | children = getattr(obj, 'children', []) |
16 | 24 | for child in children: |
@@ -67,7 +75,7 @@ def filter(self, btype='', name=''): |
67 | 75 | for x in self.children: |
68 | 76 | if name and isinstance(x, Key) and x.name == name: |
69 | 77 | filtered.append(x) |
70 | | - elif isinstance(x, Container) and x.__class__.__name__ == btype\ |
| 78 | + elif isinstance(x, Container) and x.__class__.__name__ == btype \ |
71 | 79 | and x.value == name: |
72 | 80 | filtered.append(x) |
73 | 81 | elif not name and btype and x.__class__.__name__ == btype: |
@@ -164,7 +172,7 @@ def filter(self, btype='', name=''): |
164 | 172 | for x in self.children: |
165 | 173 | if name and isinstance(x, Key) and x.name == name: |
166 | 174 | filtered.append(x) |
167 | | - elif isinstance(x, Container) and x.__class__.__name__ == btype\ |
| 175 | + elif isinstance(x, Container) and x.__class__.__name__ == btype \ |
168 | 176 | and x.value == name: |
169 | 177 | filtered.append(x) |
170 | 178 | elif not name and btype and x.__class__.__name__ == btype: |
@@ -507,6 +515,11 @@ def loads(data, conf=True): |
507 | 515 | index += m.end() |
508 | 516 | continue |
509 | 517 |
|
| 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 | + |
510 | 523 | double = r'\s*"[^"]*"' |
511 | 524 | single = r'\s*\'[^\']*\'' |
512 | 525 | normal = r'\s*[^;\s]*' |
|
0 commit comments