Skip to content

Commit 458400c

Browse files
committed
Simplified regex for key
1 parent b2eb8d5 commit 458400c

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

nginx.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -477,19 +477,11 @@ def loads(data, conf=True):
477477
index += m.end()
478478
continue
479479

480-
key_with_quoted = r'^\s*(\S*?)\s*"([^"]+)";?|\'([^\']+)\';?|\\S+;?'
481-
key_wo_quoted = r'^\s*([a-zA-Z0-9-_]+?)\s+(.+?);'
482-
m1 = re.compile(key_with_quoted, re.S).search(data[index:])
483-
m2 = re.compile(key_wo_quoted, re.S).search(data[index:])
484-
if m1 and m2:
485-
if m1.start() <= m2.start():
486-
m = m1
487-
else:
488-
m = m2
489-
else:
490-
m = m1 or m2
480+
string_combos = r'[^;]+|"([^"]+)"|\'([^\']+)\''
481+
key = r'^\s*({})\s+({})\s*([^;]*?);'.format(string_combos, string_combos)
482+
m = re.compile(key, re.S).search(data[index:])
491483
if m:
492-
k = Key(m.group(1), m.group(2))
484+
k = Key(m.group(1), m.group(4) + m.group(7))
493485
if lopen and isinstance(lopen[0], (Container, Server)):
494486
lopen[0].add(k)
495487
else:

0 commit comments

Comments
 (0)