Opened 9 years ago
Closed 9 years ago
#867 closed defect (invalid)
location regexp does not escape ";" between "\Q" and "\E"
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | documentation | Version: | 1.2.x |
Keywords: | Cc: | ||
uname -a: | Linux ns1 3.2.0-4-686-pae #1 SMP Debian 3.2.68-1+deb7u3 i686 GNU/Linux | ||
nginx -V: |
nginx version: nginx/1.2.1
TLS SNI support enabled configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-pcre-jit --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/nginx-qJN2mU/nginx-1.2.1/debian/modules/nginx-auth-pam --add-module=/build/nginx-qJN2mU/nginx-1.2.1/debian/modules/nginx-echo --add-module=/build/nginx-qJN2mU/nginx-1.2.1/debian/modules/nginx-upstream-fair --add-module=/build/nginx-qJN2mU/nginx-1.2.1/debian/modules/nginx-dav-ext-module |
Description
We need to redirect http://www.cancione.net/ame-tateeot;SUI3bFpISzZ1Um8=
trying this:
location ~* \Q/ame-tateeot\;SUI3bFpISzZ1Um8=\E* {
return 302 http://.../;
} # location
redirects only http://www.cancione.net/ame-tateeot\;SUI3bFpISzZ1Um8= - that's right, because symbols between \Q and \E are escaped and used as-is.
Trying this:
location ~* \Q/ame-tateeot;SUI3bFpISzZ1Um8=\E* {
return 302 http://.../;
} # location
cause error:
nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/sites-enabled/blocked:11632
That's not right, because ';' beetween \Q and \E is not escaped and used as part of location directive. We think it's a error.
For override this bug we use next construction:
location ~* \Q/ame-tateeot\E\;\QSUI3bFpISzZ1Um8=\E* {
return 302 http://.../;
} # location
Regular expressions are not part of nginx configuration syntax, and you have to escape nginx special characters in regular expressions regardless of what they are expected to mean in a regular expression itself and their position within the regular expression. Simplest way to do this is to use single or or double quotes around the regular expression if it contains ';' or '}', as suggested by the if directive documentation:
Additionally, in this particular case regular expression looks unneeded. An exact match location should be better choice, e.g.: