From df8901ec7baee07bb06a2a0aed1d0bea7e5716a4 Mon Sep 17 00:00:00 2001 From: Daniel Gruno Date: Sat, 13 Apr 2013 06:24:11 +0000 Subject: [PATCH] fix docs on regex matching, change the actual ordering of arguments to match the docs, and enforce AP_MAX_REG_MATCH in the function, should it somehow return more matches than we have allocated git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1467557 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/mod/mod_lua.xml | 2 +- modules/lua/lua_request.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/manual/mod/mod_lua.xml b/docs/manual/mod/mod_lua.xml index 1a47bf32c7..944b0a705e 100644 --- a/docs/manual/mod/mod_lua.xml +++ b/docs/manual/mod/mod_lua.xml @@ -874,7 +874,7 @@ end r:regex(string, pattern) -- Runs a regular expression match on a string, returning captures if matched: -local matches = r:regex("foo bar baz", "foo (%w+) (%S*)") +local matches = r:regex("foo bar baz", "foo (\w+) (\S*)") if matches then r:puts("The regex matched, and the last word captured ($2) was: " .. matches[2]) end diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 4903a034dc..8f9aae380e 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -908,8 +908,8 @@ static int lua_ap_regex(lua_State *L) luaL_checktype(L, 2, LUA_TSTRING); luaL_checktype(L, 3, LUA_TSTRING); r = ap_lua_check_request_rec(L, 1); - pattern = lua_tostring(L, 2); - source = lua_tostring(L, 3); + source = lua_tostring(L, 2); + pattern = lua_tostring(L, 3); flags = luaL_optinteger(L, 4, 0); rv = ap_regcomp(®ex, pattern, flags); @@ -928,7 +928,7 @@ static int lua_ap_regex(lua_State *L) } lua_newtable(L); - for (i = 0; i <= regex.re_nsub; i++) { + for (i = 0; i <= regex.re_nsub && i <= AP_MAX_REG_MATCH; i++) { lua_pushinteger(L, i); if (matches[i].rm_so >= 0 && matches[i].rm_eo >= 0) lua_pushstring(L, -- 2.40.0