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):
436
436
index += m .end ()
437
437
continue
438
438
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 :])
440
440
if m :
441
441
l = Location (m .group (1 ))
442
442
lopen .insert (0 , l )
443
443
index += m .end ()
444
444
continue
445
445
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 :])
447
447
if m :
448
448
ifs = If (m .group (1 ))
449
449
lopen .insert (0 , ifs )
450
450
index += m .end ()
451
451
continue
452
452
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 :])
454
454
if m :
455
455
u = Upstream (m .group (1 ))
456
456
lopen .insert (0 , u )
457
457
index += m .end ()
458
458
continue
459
459
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 :])
461
461
if m :
462
462
g = Geo (m .group (1 ))
463
463
lopen .insert (0 , g )
464
464
index += m .end ()
465
465
continue
466
466
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 :])
468
468
if m :
469
469
g = Map (m .group (1 ))
470
470
lopen .insert (0 , g )
471
471
index += m .end ()
472
472
continue
473
473
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
+
474
481
m = re .compile (r'^(\s*)#\s*(.*?)\n' , re .S ).search (data [index :])
475
482
if m :
476
483
c = Comment (m .group (2 ), inline = '\n ' not in m .group (1 ))
Original file line number Diff line number Diff line change 155
155
}
156
156
"""
157
157
158
+ TESTBLOCK_CASE_8 = """
159
+ location /M01 {
160
+ proxy_pass http://backend;
161
+ limit_except GET POST {deny all;}
162
+ }
163
+ """
158
164
159
165
160
166
class TestPythonNginx (unittest .TestCase ):
@@ -241,6 +247,18 @@ def test_filtering(self):
241
247
self .assertEqual (len (data .server .filter ('Key' , 'mykey' )), 1 )
242
248
self .assertEqual (data .server .filter ('Key' , 'nothere' ), [])
243
249
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
+
244
262
245
263
if __name__ == '__main__' :
246
264
unittest .main ()
You can’t perform that action at this time.
0 commit comments