# Odd behavior from ndk.set\_var.set\_quote\_sql\_str

**URL:** <https://www.ruby-forum.com/t/odd-behavior-from-ndk-set-var-set-quote-sql-str/213220>\
**Category:** NGINX\
**Created:** [October 26, 2011, 6:59pm UTC](https://www.ruby-forum.com/t/odd-behavior-from-ndk-set-var-set-quote-sql-str/213220 "2011-10-26T18:59:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [October 26, 2011, 6:59pm UTC](https://www.ruby-forum.com/t/odd-behavior-from-ndk-set-var-set-quote-sql-str/213220/1 "2011-10-26T18:59:48Z")

</div>

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](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:

> **[odd behavior from ndk.set\_var.set\_quote\_sql\_str](https://forum.nginx.org/read.php?2,217260,217260#msg-217260)**
>
> 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(vers

---

<div class="post-metadata">

**Author:** ![dannynoonan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@dannynoonan](https://www.ruby-forum.com/u/dannynoonan)\
**Post date:** [October 27, 2011, 1:58pm UTC](https://www.ruby-forum.com/t/odd-behavior-from-ndk-set-var-set-quote-sql-str/213220/2 "2011-10-27T13:58:11Z")

</div>

On Thu, Oct 27, 2011 at 12:59 AM, dannynoonan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![dannynoonan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@dannynoonan](https://www.ruby-forum.com/u/dannynoonan)\
**Post date:** [October 27, 2011, 7:29pm UTC](https://www.ruby-forum.com/t/odd-behavior-from-ndk-set-var-set-quote-sql-str/213220/3 "2011-10-27T19:29:31Z")

</div>

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:

> **[Re: odd behavior from ndk.set\_var.set\_quote\_sql\_str](https://forum.nginx.org/read.php?2,217260,217433#msg-217433)**
>
> 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(vers

---

<div class="post-metadata">

**Author:** ![dannynoonan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@dannynoonan](https://www.ruby-forum.com/u/dannynoonan)\
**Post date:** [October 28, 2011, 1:39am UTC](https://www.ruby-forum.com/t/odd-behavior-from-ndk-set-var-set-quote-sql-str/213220/4 "2011-10-28T01:39:37Z")

</div>

ndk.set\_var.set\_quote\_sql\_str works as expected with 1.0.8.25

[david@dev-3 ~]# curl [http://localhost:8080/luaset](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:

> **[Re: odd behavior from ndk.set\_var.set\_quote\_sql\_str](https://forum.nginx.org/read.php?2,217260,217445#msg-217445)**
>
> 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(vers

---

<div class="post-metadata">

**Author:** ![dannynoonan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@dannynoonan](https://www.ruby-forum.com/u/dannynoonan)\
**Post date:** [October 28, 2011, 5:19pm UTC](https://www.ruby-forum.com/t/odd-behavior-from-ndk-set-var-set-quote-sql-str/213220/5 "2011-10-28T17:19:50Z")

</div>

On Fri, Oct 28, 2011 at 7:39 AM, dannynoonan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 68o32c9e64o2sc9j5co30c1g  
> ‘2011.10.13+0000’

Great! Happy Lua hacking!

Thanks!  
-agentzh

---

<div class="post-metadata">

**Author:** ![dannynoonan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@dannynoonan](https://www.ruby-forum.com/u/dannynoonan)\
**Post date:** [October 28, 2011, 5:20pm UTC](https://www.ruby-forum.com/t/odd-behavior-from-ndk-set-var-set-quote-sql-str/213220/6 "2011-10-28T17:20:28Z")

</div>

On Fri, Oct 28, 2011 at 1:28 AM, dannynoonan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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! 😃

Thanks!  
-agentzh
