File tree Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -436,41 +436,48 @@ def loads(data, conf=True):
436436 index += m .end ()
437437 continue
438438
439- m = re .compile (r'^\s*location\s*(.*?\S+ )\s*{' , re .S ).search (data [index :])
439+ m = re .compile (r'^\s*location\s*(.*?)\s*{' , re .S ).search (data [index :])
440440 if m :
441441 l = Location (m .group (1 ))
442442 lopen .insert (0 , l )
443443 index += m .end ()
444444 continue
445445
446- m = re .compile (r'^\s*if\s*(.*?\S+ )\s*{' , re .S ).search (data [index :])
446+ m = re .compile (r'^\s*if\s*(.*?)\s*{' , re .S ).search (data [index :])
447447 if m :
448448 ifs = If (m .group (1 ))
449449 lopen .insert (0 , ifs )
450450 index += m .end ()
451451 continue
452452
453- m = re .compile (r'^\s*upstream\s*(.*?\S+ )\s*{' , re .S ).search (data [index :])
453+ m = re .compile (r'^\s*upstream\s*(.*?)\s*{' , re .S ).search (data [index :])
454454 if m :
455455 u = Upstream (m .group (1 ))
456456 lopen .insert (0 , u )
457457 index += m .end ()
458458 continue
459459
460- m = re .compile (r'^\s*geo\s*(.*?\S+ )\s*{' , re .S ).search (data [index :])
460+ m = re .compile (r'^\s*geo\s*(.*?)\s*{' , re .S ).search (data [index :])
461461 if m :
462462 g = Geo (m .group (1 ))
463463 lopen .insert (0 , g )
464464 index += m .end ()
465465 continue
466466
467- m = re .compile (r'^\s*map\s*(.*?\S+ )\s*{' , re .S ).search (data [index :])
467+ m = re .compile (r'^\s*map\s*(.*?)\s*{' , re .S ).search (data [index :])
468468 if m :
469469 g = Map (m .group (1 ))
470470 lopen .insert (0 , g )
471471 index += m .end ()
472472 continue
473473
474+ m = re .compile (r'^\s*limit_except\s*(.*?)\s*{' , re .S ).search (data [index :])
475+ if m :
476+ l = LimitExcept (m .group (1 ))
477+ lopen .insert (0 , l )
478+ index += m .end ()
479+ continue
480+
474481 m = re .compile (r'^(\s*)#\s*(.*?)\n' , re .S ).search (data [index :])
475482 if m :
476483 c = Comment (m .group (2 ), inline = '\n ' not in m .group (1 ))
Original file line number Diff line number Diff line change 155155}
156156"""
157157
158+ TESTBLOCK_CASE_8 = """
159+ location /M01 {
160+ proxy_pass http://backend;
161+ limit_except GET POST {deny all;}
162+ }
163+ """
158164
159165
160166class TestPythonNginx (unittest .TestCase ):
@@ -241,6 +247,18 @@ def test_filtering(self):
241247 self .assertEqual (len (data .server .filter ('Key' , 'mykey' )), 1 )
242248 self .assertEqual (data .server .filter ('Key' , 'nothere' ), [])
243249
250+ def test_limit_expect (self ):
251+ data = nginx .loads (TESTBLOCK_CASE_8 )
252+ self .assertEqual (len (data .filter ("Location" )), 1 )
253+ self .assertEqual (len (data .filter ("Location" )[0 ].children ), 2 )
254+ self .assertEqual (len (data .filter ("Location" )[0 ].filter ("LimitExcept" )), 1 )
255+ limit_except = data .filter ("Location" )[0 ].filter ("LimitExcept" )[0 ]
256+ self .assertEqual (limit_except .value , "GET POST" )
257+ self .assertEqual (len (limit_except .children ), 1 )
258+ first_key = limit_except .filter ("Key" )[0 ]
259+ self .assertEqual (first_key .name , "deny" )
260+ self .assertEqual (first_key .value , "all" )
261+
244262
245263if __name__ == '__main__' :
246264 unittest .main ()
You can’t perform that action at this time.
0 commit comments