Welcome! Log In Create A New Profile

Advanced

Special characters in variable names

Posted by Yumi 
Special characters in variable names
July 18, 2013 07:35PM
I wasn't able to find much documentation on the syntax of variables in nginx.
In particular, how are special characters handled in the $arg_NAME and $cookie_NAME variables?

The following doesn't seem to work for me:
$cookie_group[key]

Does there need to be some sort of escaping to handle these?
Thanks in advance!
Re: Special characters in variable names
July 20, 2013 04:24AM
So I went through the source code and it appears that anything other than a letter, number or underscore is explicitly disallowed in variable names.
However, you can use ${varname} type syntax.

Hence, it's possible to abuse these brackets to allow the use of more characters. Here's my code patch:

--- src/http/ngx_http_script.c
+++ src/http/ngx_http_script.c
@@ -394,11 +394,11 @@

if (ch == '}' && bracket) {
i++;
bracket = 0;
break;
- }
+ } else if (bracket) continue;

if ((ch >= 'A' && ch <= 'Z')
|| (ch >= 'a' && ch <= 'z')
|| (ch >= '0' && ch <= '9')
|| ch == '_')

As it just makes the parser a bit more lenient, it shouldn't cause any side effects.

The above patch allows you to use most characters in variable names, so you could refer to cookies with special names using ${cookie_group[key]}

Hope this post is useful to anyone that finds it.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 165
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready