Skip to content

Commit 63d5921

Browse files
committed
do not count braces inside quotes, closes #7
1 parent f22b190 commit 63d5921

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ MANIFEST
22
dist
33
build
44
*.pyc
5+
*.egg-info

nginx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def loads(data, conf=True):
414414
f = Conf() if conf else []
415415
lopen = []
416416
for line in data.split('\n'):
417+
line_outside_quotes = re.sub(r'"([^"]+)"|\'([^\']+)\'|\\S+', '', line)
417418
if re.match(r'\s*server\s*{', line):
418419
s = Server()
419420
lopen.insert(0, s)
@@ -444,8 +445,8 @@ def loads(data, conf=True):
444445
if "#" not in kname:
445446
k = Key(kname, kval)
446447
lopen[0].add(k)
447-
if re.match(r'.*}', line):
448-
closenum = len(re.findall('}', line))
448+
if re.match(r'.*}', line_outside_quotes):
449+
closenum = len(re.findall('}', line_outside_quotes))
449450
while closenum > 0:
450451
if isinstance(lopen[0], Server):
451452
f.add(lopen[0]) if conf else f.append(lopen[0])

0 commit comments

Comments
 (0)