[Patch] Re: Directive "map" not working with regex key and value that like "$1"
Maxim Dounin
mdounin at mdounin.ru
Mon Dec 22 01:19:45 UTC 2014
Hello!
On Sun, Dec 21, 2014 at 11:03:24AM +0800, kindy wrote:
> The root cause there are both. var_values & value_hashs.
> when used with regex key, we should not use var_values,
> because numbered capture are not registered as nginx variable.
>
> so directive like "~(.+) $1;" will add $1 into var_values by mistake, but
> latter regex will not add this variable..
No. The root cause is that $1 variables are special and can't be
handled using the ngx_http_get_variable_index() function. As
map{} uses the ngx_http_get_variable_index(), it doesn't
understand $1..$9 variables.
If you want to access captures in resulting values in a map,
you can use named captures instead:
map $foo $bar {
~(<temp>.*) $temp;
}
> ---start of patch---
>
> --- nginx-1.1.19-orig/src/http/modules/ngx_http_map_module.c 2012-01-18
> 23:07:43.000000000 +0800
> +++ nginx-1.1.19-fixe/src/http/modules/ngx_http_map_module.c 2014-12-20
> 10:42:01.000000000 +0800
> @@ -403,6 +403,10 @@
> return ngx_conf_parse(cf, &file);
> }
>
> +#if (NGX_PCRE)
> + if (!value[0].len || value[0].data[0] != '~') {
> +#endif
> +
> if (value[1].data[0] == '$') {
> name = value[1];
> name.len--;
This patch is wrong, it will prevent variable expansion in
resulting values if a source value is specified using a regular
expression.
[...]
--
Maxim Dounin
http://nginx.org/
More information about the nginx-devel
mailing list