Hello!
On Thu, Jul 3, 2014 at 6:14 AM, Alonso Superuser wrote:
> Question 1 :
> Not sure how the below was supposed to work...but I see that lua module does
> not log an error immediately in case "pcre_compile" API of PCRE library
> returns error.
To quote the official ngx_lua documentation for ngx.re.match
(https://github.com/openresty/lua-nginx-module#ngxrematch ):
"Only the first occurrence of the match is returned, or nil if no
match is found. In case of errors, like seeing a bad regular
expression or exceeding the PCRE stack limit, nil and a string
describing the error will be returned."
> It pushes the "err.data" but the caller of
> "ngx_http_lua_ngx_re_match_helper" does not seem to be using it.
>
It is up to you (the caller) to handle the error on the Lua land. To
quote the code example in the official documentation:
"
local m, err = ngx.re.match("hello, 1234", "[0-9]+")
if m then
-- m[0] == "1234"
else
if err then
ngx.log(ngx.ERR, "error: ", err)
return
end
ngx.say("match not found")
end
"
> End result is one does not see any error and the "re.match()" API fails.
Again, it is your responsibility to do proper error handling here.
Many of the Lua API functions in ngx_lua returns the error string
gracefully rather than throwing out an exception aggressively, just as
many of the standard Lua API functions.
> Can
> anyone confirm if it is the bug in lua module ?
No, it is not a bug.
> Who is supposed to use the
> pushed err.string and log it?
>
You :)
Some applications may choose to handle the error some other ways than
logging it.
> Question 2 :
> lua directive "lua_regex_match_limit" is used to change the match_limit of
> PCRE library. This gets used in "pcre_exec" API, but is not used in
> "pcre_compile" API.
According to the PCRE man page (http://www.pcre.org/pcre.txt), the
PCRE_EXTRA_MATCH_LIMIT field bit is for pcre_exec() instead of
pcre_compile().
There have been actually (passing) test cases for this "match limit"
feature in ngx_lua's official test suite, for instance,
https://github.com/openresty/lua-nginx-module/blob/master/t/047-match-jit.t#L139
> So in which conditions is this directive useful...as in
> this particular case changing this directive does not make any difference
>
> Test case :
> Have a regular expression like :
> ngx.re.match(string.lower(ngx.var.request_uri), "/abc/1|/abc/2|/abc/3 <so on
> for 5000 times>")
> (i.e. there is an ORed list of URIs from /abc/1 to /abc/5000)
>
If you believe it does not work for you as you expected, then you
should probably write a standalone PCRE C test program and report the
issue to the PCRE maintainers instead. And it is known that PCRE's
match limit might have some quirks due to issues in its own
implementation.
Best regards,
-agentzh