Permalink
Browse files

ensured that proper error message is always thrown when the iterator …

…returned by ngx.re.gmatch is used in the context of another nginx request.
  • Loading branch information...
1 parent e73e244 commit 3eab7b0361c8d4619a96b3ae38ea1ab0db172620 @agentzh agentzh committed Jul 19, 2012
Showing with 61 additions and 2 deletions.
  1. +4 −1 src/ngx_http_lua_regex.c
  2. +57 −1 t/035-gmatch.t
View
@@ -1721,14 +1721,17 @@ ngx_http_lua_ngx_re_gmatch_cleanup(void *data)
if (ctx) {
if (ctx->regex_sd) {
dd("free study data");
- ngx_http_lua_regex_free_study_data(ctx->request->pool, ctx->regex_sd);
+ ngx_http_lua_regex_free_study_data(ctx->request->pool,
+ ctx->regex_sd);
ctx->regex_sd = NULL;
}
if (ctx->cleanup) {
*ctx->cleanup = NULL;
ctx->cleanup = NULL;
}
+
+ ctx->request = NULL;
}
return;
View
@@ -9,7 +9,9 @@ use Test::Nginx::Socket;
repeat_each(2);
-plan tests => repeat_each() * (blocks() * 2);
+plan tests => repeat_each() * (blocks() * 2 + 1);
+
+our $HtmlDir = html_dir;
#no_diff();
#no_long_string();
@@ -426,3 +428,57 @@ hello
--- response_body
done
+
+
+=== TEST 19: gmatch iterator used by another request
+--- http_config eval
+ "lua_package_path '$::HtmlDir/?.lua;;';"
+--- config
+ location /main {
+ content_by_lua '
+ package.loaded.foo = nil
+
+ local res = ngx.location.capture("/t")
+ if res.status == 200 then
+ ngx.print(res.body)
+ else
+ ngx.say("sr failed: ", res.status)
+ end
+
+ res = ngx.location.capture("/t")
+ if res.status == 200 then
+ ngx.print(res.body)
+ else
+ ngx.say("sr failed: ", res.status)
+ end
+ ';
+ }
+
+ location /t {
+ content_by_lua '
+ local foo = require "foo"
+ local m = foo.go()
+ ngx.say(m and "matched" or "no")
+ ';
+ }
+--- user_files
+>>> foo.lua
+module("foo", package.seeall)
+
+local it
+
+function go()
+ if not it then
+ it = ngx.re.gmatch("hello, world", "[a-z]+")
+ end
+
+ return it()
+end
+--- request
+ GET /main
+--- response_body
+matched
+sr failed: 500
+--- error_log
+attempt to use ngx.re.gmatch iterator in a request that did not create it
+

0 comments on commit 3eab7b0

Please sign in to comment.