Skip to content

Commit 39ff3e6

Browse files
committed
added tests for using the ngx. API functions in the user callback functions for ngx.re.gsub's replacement. these tests exposed a bug in lua-resty-core.
1 parent 521e4f4 commit 39ff3e6

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

t/037-gsub.t

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ log_level('warn');
99

1010
repeat_each(2);
1111

12-
plan tests => repeat_each() * (blocks() * 2 + 14);
12+
plan tests => repeat_each() * (blocks() * 2 + 16);
1313

1414
#no_diff();
1515
no_long_string();
@@ -609,3 +609,69 @@ Original bad result: .b.d
609609
--- response_body
610610
.b.cd
611611
612+
613+
614+
=== TEST 27: use of ngx.req.get_headers in the user callback
615+
--- config
616+
617+
location = /t {
618+
content_by_lua '
619+
local data = [[
620+
INNER
621+
INNER
622+
]]
623+
624+
-- ngx.say(data)
625+
626+
local res = ngx.re.gsub(data, "INNER", function(inner_matches)
627+
local header = ngx.req.get_headers()["Host"]
628+
-- local header = ngx.var["http_HEADER"]
629+
return "INNER_REPLACED"
630+
end, "s")
631+
632+
ngx.print(res)
633+
';
634+
}
635+
636+
--- request
637+
GET /t
638+
--- response_body
639+
INNER_REPLACED
640+
INNER_REPLACED
641+
642+
--- no_error_log
643+
[error]
644+
645+
646+
647+
=== TEST 28: use of ngx.var in the user callback
648+
--- config
649+
650+
location = /t {
651+
content_by_lua '
652+
local data = [[
653+
INNER
654+
INNER
655+
]]
656+
657+
-- ngx.say(data)
658+
659+
local res = ngx.re.gsub(data, "INNER", function(inner_matches)
660+
-- local header = ngx.req.get_headers()["Host"]
661+
local header = ngx.var["http_HEADER"]
662+
return "INNER_REPLACED"
663+
end, "s")
664+
665+
ngx.print(res)
666+
';
667+
}
668+
669+
--- request
670+
GET /t
671+
--- response_body
672+
INNER_REPLACED
673+
INNER_REPLACED
674+
675+
--- no_error_log
676+
[error]
677+

0 commit comments

Comments
 (0)