# Capture in if - escaping depends on location bug

**URL:** <https://www.ruby-forum.com/t/capture-in-if-escaping-depends-on-location-bug/218128>\
**Category:** NGINX\
**Created:** [March 22, 2012, 3:34am UTC](https://www.ruby-forum.com/t/capture-in-if-escaping-depends-on-location-bug/218128 "2012-03-22T03:34:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 22, 2012, 3:34am UTC](https://www.ruby-forum.com/t/capture-in-if-escaping-depends-on-location-bug/218128/1 "2012-03-22T03:34:27Z")

</div>

I am capturing some data in if, and then redirecting on what was  
captured. The problem is, that captured data is escaped if url contains  
“%” char, and may be others, and do not escaped if it does not. I have  
simple config:

Having simple config

```
location / {
    set $out "http://example.com/?a=b&c=d%";
   if ( $out ~ "(.*)" ){
        set $z $1;
        rewrite ^ $z redirect;
    }

```

Making 2 requests:

telnet 127.0.0.1 80  
Trying 127.0.0.1…  
Connected to 127.0.0.1.  
Escape character is ‘^]’.  
GET / HTTP/1.0  
Host: [my.ru](http://my.ru)

HTTP/1.1 302 Moved Temporarily  
Server: nginx/1.0.14  
Date: Thu, 22 Mar 2012 02:20:14 GMT  
Content-Type: text/html  
Content-Length: 161  
Connection: close  
Location: [Example Domain](http://example.com/?a=b&c=d%25)

302 Found
# 302 Found

* * *
nginx/1.0.14 Connection closed by foreign host.

telnet 127.0.0.1 80  
Trying 127.0.0.1…  
Connected to 127.0.0.1.  
Escape character is ‘^]’.  
GET /% HTTP/1.0  
Host: [my.ru](http://my.ru)

HTTP/1.1 302 Moved Temporarily  
Server: nginx/1.0.14  
Date: Thu, 22 Mar 2012 02:21:00 GMT  
Content-Type: text/html  
Content-Length: 161  
Connection: close  
Location: [Example Domain](http://example.com/?a=b%26c=d%25)

302 Found
# 302 Found

* * *
nginx/1.0.14 Connection closed by foreign host.

Expected the same location as in first request, but got another.  
Tested on nginx-1.0.14 , nginx-1.0.6 .

Posted at Nginx Forum:

> **[capture in if - escaping depends on location bug](https://forum.nginx.org/read.php?2,224209,224209#msg-224209)**
>
> I am capturing some data in if, and then redirecting on what was captured. The problem is, that captured data is escaped if url contains "%" char, and may be others, and do not escaped if it does not. I have simple config: Having simple...
