Hello!
I believe I found a limitation in the resty.core implemention of ngx.re.(g)sub. Examine the following (very contrived) example:
content_by_lua '
local lookup = function(m)
-- note we are returning a number type here
return 5
end
local newstr, n, err = ngx.re.sub("hello, 1234", "([0-9])[0-9]", lookup, "oij")
ngx.say(newstr)
';
This perform as expected:
$ curl localhost/re-test
hello, 55
However, when we enable resty.core, this fails with the following:
2016/01/29 11:09:30 [debug] 23491#0: *2 [lua] content_by_lua(nginx.conf:237):3: replace(): m[0] is 12
2016/01/29 11:09:30 [debug] 23491#0: *2 lua resume returned 2
2016/01/29 11:09:30 [error] 23491#0: *2 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/core/regex.lua:641: attempt to get length of local 'bit' (a number value)
stack traceback:
coroutine 0:
/usr/local/openresty/lualib/resty/core/regex.lua: in function 'gsub'
content_by_lua(nginx.conf:237):7: in function <content_by_lua(nginx.conf:237):1>, client: 127.0.0.1, server: localhost, request: "GET /re-test HTTP/1.1", host: "localhost"
Obviously, we can see why in regex.lua this fails. I could make this work by casting the return in my lookup function via tostring(), but later in my actual use case I need to perform numeric comparison, so forcing two castes as a workaround seems wasteful. Any thoughts here? Thank you!