From 63d59214d6a6136f1277c7247b51a22f4a3e7b56 Mon Sep 17 00:00:00 2001 From: Jacob Cook Date: Sat, 14 Jan 2017 17:52:15 -0500 Subject: [PATCH] do not count braces inside quotes, closes #7 --- .gitignore | 1 + nginx.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d457f7d..e796898 100755 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ MANIFEST dist build *.pyc +*.egg-info diff --git a/nginx.py b/nginx.py index 4630320..cbbce4f 100755 --- a/nginx.py +++ b/nginx.py @@ -414,6 +414,7 @@ def loads(data, conf=True): f = Conf() if conf else [] lopen = [] for line in data.split('\n'): + line_outside_quotes = re.sub(r'"([^"]+)"|\'([^\']+)\'|\\S+', '', line) if re.match(r'\s*server\s*{', line): s = Server() lopen.insert(0, s) @@ -444,8 +445,8 @@ def loads(data, conf=True): if "#" not in kname: k = Key(kname, kval) lopen[0].add(k) - if re.match(r'.*}', line): - closenum = len(re.findall('}', line)) + if re.match(r'.*}', line_outside_quotes): + closenum = len(re.findall('}', line_outside_quotes)) while closenum > 0: if isinstance(lopen[0], Server): f.add(lopen[0]) if conf else f.append(lopen[0])