# Embedded variable $cookie\_YYY and "-" symbol

**URL:** <https://www.ruby-forum.com/t/embedded-variable-cookie-yyy-and-symbol/226687>\
**Category:** NGINX\
**Created:** [February 18, 2013, 12:55pm UTC](https://www.ruby-forum.com/t/embedded-variable-cookie-yyy-and-symbol/226687 "2013-02-18T12:55:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igor\_Karymov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e99b99/32.png) [@Igor\_Karymov](https://www.ruby-forum.com/u/Igor_Karymov)\
**Post date:** [February 18, 2013, 12:55pm UTC](https://www.ruby-forum.com/t/embedded-variable-cookie-yyy-and-symbol/226687/1 "2013-02-18T12:55:18Z")

</div>

Hi all. I observe unexpected behavior when trying to use $cookie\_YYY  
embended variable when cookie name include “-” symbol.

set $uwaver $cookie\_un-uwa-version;

$uwaver always equal to “-uwa-version” string instead of real cookie  
value.

maybe i should use some kind of escaping here?

nginx -v  
nginx version: nginx/1.2.7

uname -a  
Linux cabal 3.2.0-37-generic #58-Ubuntu SMP Thu Jan 24 15:28:10 UTC 2013  
x86\_64 x86\_64 x86\_64 GNU/Linux

---

<div class="post-metadata">

**Author:** ![Igor\_Karymov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e99b99/32.png) [@Igor\_Karymov](https://www.ruby-forum.com/u/Igor_Karymov)\
**Post date:** [February 18, 2013, 1:36pm UTC](https://www.ruby-forum.com/t/embedded-variable-cookie-yyy-and-symbol/226687/2 "2013-02-18T13:36:17Z")

</div>

On Mon, Feb 18, 2013 at 03:54:33PM +0400, Igor Karymov wrote:

Hi there,

> set $uwaver $cookie\_un-uwa-version;
> 
> $uwaver always equal to “-uwa-version” string instead of real cookie value.
> 
> maybe i should use some kind of escaping here?

I believe that the reason is that there are some characters which are  
valid in cookie names, but which are not valid in nginx variable names;  
and I believe that the only way to access them in nginx.conf is to parse  
$http\_cookie yourself.

There is a similar problem with the $arg\_\* variables.

Both the $cookie\_ and the $arg\_ variables are convenience features,  
and they work well provided that you restrict your inputs appropriately.

I’m not sure how much work it would be to create a patch allow, for  
example, ${var.iab-le} as a way of accessing a variable named like that;  
but I guess that it has been “more work than just avoiding or working  
around those variable names” for everyone who has hit the issue so far.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Igor\_Karymov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e99b99/32.png) [@Igor\_Karymov](https://www.ruby-forum.com/u/Igor_Karymov)\
**Post date:** [February 18, 2013, 1:54pm UTC](https://www.ruby-forum.com/t/embedded-variable-cookie-yyy-and-symbol/226687/3 "2013-02-18T13:54:00Z")

</div>

Francis D. wrote in post #1097580:

> On Mon, Feb 18, 2013 at 03:54:33PM +0400, Igor Karymov wrote:
> 
> Hi there,
> 
> > set $uwaver $cookie\_un-uwa-version;
> > 
> > $uwaver always equal to “-uwa-version” string instead of real cookie value.
> > 
> > maybe i should use some kind of escaping here?
> 
> I believe that the reason is that there are some characters which are  
> valid in cookie names, but which are not valid in nginx variable names;  
> and I believe that the only way to access them in nginx.conf is to parse  
> $http\_cookie yourself.
> 
> There is a similar problem with the $arg\_\* variables.
> 
> Both the $cookie\_ and the $arg\_ variables are convenience features,  
> and they work well provided that you restrict your inputs appropriately.
> 
> I’m not sure how much work it would be to create a patch allow, for  
> example, ${var.iab-le} as a way of accessing a variable named like that;  
> but I guess that it has been “more work than just avoiding or working  
> around those variable names” for everyone who has hit the issue so far.
> 
> ## f
> 
> Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

You can work around this for now with a quirk of the way the map module  
works. It treats any value beginning with $ as a variable name and  
skips some of the validation, so you can:

# The first variable is irrelevant, $is\_args just doesn’t

# do much processing.

map $is\_args $uwaver {  
default $cookie\_un-uwa-version;  
}

This workaround may become invalid if the map module is ever extended to  
accept complex values, but it just worked in a test for me.

Jon

---

<div class="post-metadata">

**Author:** ![Igor\_Karymov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e99b99/32.png) [@Igor\_Karymov](https://www.ruby-forum.com/u/Igor_Karymov)\
**Post date:** [February 18, 2013, 2:10pm UTC](https://www.ruby-forum.com/t/embedded-variable-cookie-yyy-and-symbol/226687/4 "2013-02-18T14:10:49Z")

</div>

This workaround has solve my issues. Thank you!
