You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by hu...@apache.org on 2013/04/13 08:24:12 UTC

svn commit: r1467557 - in /httpd/httpd/trunk: docs/manual/mod/mod_lua.xml modules/lua/lua_request.c

Author: humbedooh
Date: Sat Apr 13 06:24:11 2013
New Revision: 1467557

URL: http://svn.apache.org/r1467557
Log:
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

Modified:
    httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
    httpd/httpd/trunk/modules/lua/lua_request.c

Modified: httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_lua.xml?rev=1467557&r1=1467556&r2=1467557&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_lua.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_lua.xml Sat Apr 13 06:24:11 2013
@@ -874,7 +874,7 @@ end
 <highlight language="lua">
 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

Modified: httpd/httpd/trunk/modules/lua/lua_request.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1467557&r1=1467556&r2=1467557&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_request.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_request.c Sat Apr 13 06:24:11 2013
@@ -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(&regex, 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,