Skip to content

Commit df5bf1d

Browse files
thibaultchaagentzh
authored andcommitted
bugfix: ignore unexpected closing long-brackets in '*_by_lua_block' directives.
Signed-off-by: Yichun Zhang (agentzh) <[email protected]>
1 parent e677159 commit df5bf1d

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/ngx_http_lua_directive.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,20 +1417,8 @@ ngx_http_lua_conf_lua_block_parse(ngx_conf_t *cf, ngx_command_t *cmd)
14171417
break;
14181418

14191419
case FOUND_LBRACKET_STR:
1420-
1421-
break;
1422-
14231420
case FOUND_LBRACKET_CMT:
1424-
1425-
break;
1426-
14271421
case FOUND_RIGHT_LBRACKET:
1428-
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1429-
"unexpected lua closing long-bracket");
1430-
goto failed;
1431-
1432-
break;
1433-
14341422
case FOUND_COMMENT_LINE:
14351423
case FOUND_DOUBLE_QUOTED:
14361424
case FOUND_SINGLE_QUOTED:

t/132-lua-blocks.t

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use Test::Nginx::Socket::Lua;
1010
repeat_each(2);
1111
#repeat_each(1);
1212

13-
plan tests => repeat_each() * (blocks() * 3 + 4);
13+
plan tests => repeat_each() * (blocks() * 3 + 3);
1414

1515
#no_diff();
1616
no_long_string();
@@ -405,7 +405,7 @@ hello, world!
405405
406406
407407
408-
=== TEST 16: content_by_lua_block (unexpected closing long brackets)
408+
=== TEST 16: content_by_lua_block unexpected closing long brackets must FAIL
409409
--- config
410410
location = /t {
411411
content_by_lua_block {
@@ -414,15 +414,30 @@ hello, world!
414414
}
415415
--- request
416416
GET /t
417+
--- error_code: 500
418+
--- error_log eval
419+
qr{\[error\] .*? unexpected symbol near ']'}
420+
421+
422+
423+
=== TEST 17: content_by_lua_block unexpected closing long brackets ignored (GitHub #748)
424+
--- config
425+
location = /t {
426+
content_by_lua_block {
427+
local t1, t2 = {"hello world"}, {1}
428+
ngx.say(t1[t2[1]])
429+
}
430+
}
431+
--- request
432+
GET /t
433+
--- response_body
434+
hello world
417435
--- no_error_log
418436
[error]
419-
--- error_log eval
420-
qr{\[emerg\] .*? unexpected lua closing long-bracket in .*?/nginx\.conf:41}
421-
--- must_die
422437
423438
424439
425-
=== TEST 17: simple set_by_lua_block (integer)
440+
=== TEST 18: simple set_by_lua_block (integer)
426441
--- config
427442
location /lua {
428443
set_by_lua_block $res { return 1+1 }
@@ -437,7 +452,7 @@ GET /lua
437452
438453
439454
440-
=== TEST 18: ambiguous line comments inside a long bracket string (GitHub #596)
455+
=== TEST 19: ambiguous line comments inside a long bracket string (GitHub #596)
441456
--- config
442457
location = /t {
443458
content_by_lua_block {
@@ -459,7 +474,7 @@ done
459474
460475
461476
462-
=== TEST 19: double quotes in long brackets
477+
=== TEST 20: double quotes in long brackets
463478
--- config
464479
location = /t {
465480
rewrite_by_lua_block { print([[Hey, it is "!]]) } content_by_lua_block { ngx.say([["]]) }
@@ -475,7 +490,7 @@ Hey, it is "!
475490
476491
477492
478-
=== TEST 20: single quotes in long brackets
493+
=== TEST 21: single quotes in long brackets
479494
--- config
480495
location = /t {
481496
rewrite_by_lua_block { print([[Hey, it is '!]]) } content_by_lua_block { ngx.say([[']]) }
@@ -491,7 +506,7 @@ Hey, it is '!
491506
492507
493508
494-
=== TEST 21: lexer no match due to incomplete data chunks in a fixed size buffer
509+
=== TEST 22: lexer no match due to incomplete data chunks in a fixed size buffer
495510
--- config
496511
location /test1 {
497512
content_by_lua_block {

0 commit comments

Comments
 (0)