Odd behavior from ndk.set_var.set_quote_sql_str

ndk.set_var.set_quote_sql_str sometimes treats the variable supplied as
a param as if it were an empty string. the following config:

location /luaset {
  content_by_lua "

    local version = '2011.10.13+0000'
    --ngx.say(version)
    --ngx.log(ngx.ERR, version)
    local e_version = ndk.set_var.set_encode_base32(version)
    local s_version= ndk.set_var.set_quote_sql_str(version)
    ngx.say(e_version)
    ngx.say(s_version)
  ";
}

when hit with a basic get request:
[david@dev-3]$ curl http://:8080/luaset
68o32c9e64o2sc9j5co30c1g
‘’
returns a quoted empty string.

if i uncomment either the ngx.log or ngx.say, the quoted string is not
empty:
[david@dev-3]$ curl http://honey:8080/luaset
68o32c9e64o2sc9j5co30c1g
‘2011.10.13+0000’

is there something about lua variables i don’t understand? how could
referencing the variable once before the sql conversion have an effect?
i can repro this over and over.

Posted at Nginx Forum:

On Thu, Oct 27, 2011 at 12:59 AM, dannynoonan [email protected]
wrote:

ndk.set_var.set_quote_sql_str sometimes treats the variable supplied as
a param as if it were an empty string. the following config:

Thanks for the report and the use case to reproduce the problem!

I’ve just fixed a memory uninitialization issue in ngx_lua’s
ndk.set_var.DIRECTIVE implementation which could cause the problem
that you’ve described and released ngx_lua v0.3.1rc23 to include this
fix:

https://github.com/chaoslawful/lua-nginx-module/tags

Could you please try it out on your side?

If you’re using the ngx_openresty bundle, you can also try out the
devel release 1.0.8.25 here:

http://openresty.org/#Download

Thanks!
-agentzh

Thanks! I’ll try it out and report back.

P.S. I love the ngx_openresty bundle, I’ve got a project I’ll open
source soon that utilizes it pretty heavily.

Posted at Nginx Forum:

ndk.set_var.set_quote_sql_str works as expected with 1.0.8.25

[david@dev-3 ~]# curl http://localhost:8080/luaset -D -
HTTP/1.1 200 OK
Server: ngx_openresty/1.0.8.25
Date: Thu, 27 Oct 2011 23:38:33 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive

68o32c9e64o2sc9j5co30c1g
‘2011.10.13+0000’

Posted at Nginx Forum:

On Fri, Oct 28, 2011 at 7:39 AM, dannynoonan [email protected]
wrote:

68o32c9e64o2sc9j5co30c1g
‘2011.10.13+0000’

Great! Happy Lua hacking!

Thanks!
-agentzh

On Fri, Oct 28, 2011 at 1:28 AM, dannynoonan [email protected]
wrote:

P.S. I love the ngx_openresty bundle, I’ve got a project I’ll open
source soon that utilizes it pretty heavily.

Oh, I’m looking forward to that! :smiley:

Thanks!
-agentzh