Skip to content

Commit bad8432

Browse files
author
kfang
committed
修复大括号问题
1 parent c592860 commit bad8432

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

nginx.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,16 +418,16 @@ def loads(data, conf=True):
418418
if re.match(r'\s*server\s*({.*)?$', line):
419419
s = Server()
420420
lopen.insert(0, s)
421-
if re.match(r'\s*location.*{', line):
422-
lpath = re.match(r'\s*location\s*(.*\S+)\s*{', line).group(1)
421+
if re.match(r'\s*location.*', line):
422+
lpath = re.match(r'\s*location\s*(.*\S+)\s*', line).group(1)
423423
l = Location(lpath)
424424
lopen.insert(0, l)
425425
if re.match(r'\s*if.*({.*)?$', line):
426426
ifs = re.match('\s*if\s*(.*\s+)\s*', line).group(1)
427427
ifs = If(ifs)
428428
lopen.insert(0, ifs)
429429
if re.match(r'\s*upstream.*({.*)?$', line):
430-
ups = re.match(r'\s*upstream\s*(.*\S+)\s*[^{]', line).group(1)
430+
ups = re.match(r'\s*upstream\s*(.*\S+)\s*[^{]', line).group().split()[1]
431431
u = Upstream(ups)
432432
lopen.insert(0, u)
433433
if re.match(r'\s*geo\s*\$.*\s{', line):
@@ -437,6 +437,9 @@ def loads(data, conf=True):
437437
if re.match(r'.*;', line):
438438
cmt_regex = r'(.*)#\s*(?![^\'\"]*[\'\"])'
439439
key_regex = r'.*(?:^|^\s*|{\s*)(\S+)\s(.+);'
440+
441+
oneword_regex = r'\s*(\S+[^\s+]\S+)\s*;\s*'
442+
440443
to_eval = line
441444
if re.match(cmt_regex, line):
442445
to_eval = re.match(cmt_regex, line).group(1)
@@ -448,6 +451,17 @@ def loads(data, conf=True):
448451
lopen[0].add(k)
449452
else:
450453
f.add(k) if conf else f.append(k)
454+
455+
if re.match(oneword_regex, line):
456+
kname = re.match(oneword_regex, line).group(1)
457+
k = Key(kname, '')
458+
459+
if lopen and isinstance(lopen[0], (Container, Server)):
460+
lopen[0].add(k)
461+
else:
462+
f.add(k) if conf else f.append(k)
463+
464+
451465
if re.match(r'(^(?!#)([^#]*[}]{1}\s*)$)|(\s*{$)', line_outside_quotes):
452466
closenum = len(re.findall('}', line_outside_quotes))
453467
while closenum > 0:

0 commit comments

Comments
 (0)