How to access query parameter names with '-' in it

Maxim Dounin mdounin at mdounin.ru
Thu Nov 13 14:52:38 UTC 2014


Hello!

On Thu, Nov 13, 2014 at 09:38:17AM -0500, Jonathan Kolb wrote:

> You can also accomplish this without matching in a map:
> 
> map $pipe $dashed_param {
>   default $arg_param-name;
> }

While this may currently work, I wouldn't recommend relying on 
this - as this is rather a bug than a desired behaviour.  This 
will stop working as long as support for multiple variables will 
be added to map.

Instead, I would recommend to use regexp-based parsing of the 
$args variable as Francis suggests.  This can be done trivially 
with map, like this:

    map $args $param_with_dash {
        "~(^|&)param-name=(?<temp>[^&]+)"  $temp;
    }

> (I tried a geo block first, but it expanded to a literal '$arg_param-name'
> for some reason)

The geo module only support static strings as values, so that's 
expected behaviour.

> 
> On Wed, Nov 12, 2014 at 5:43 PM, Francis Daly <francis at daoine.org> wrote:
> 
> > On Wed, Nov 12, 2014 at 03:38:03AM -0500, sudarshan wrote:
> >
> > Hi there,
> >
> > > If query parameters in the request looks like this
> > >
> > > /something.cgi?param_name=1&param-name=2
> > >
> > > I can access 'param_name' as $arg_param_name. How do I access
> > 'param-name'
> > > though? $arg_param-name will not work since as far as nginx is concerned
> > the
> > > variable name ends at $arg_param. Is there a workaround for this case?
> > Has
> > > anyone else run into a similar problem?
> >
> > If you want to avoid embedded languages, you could match-and-extract
> > from $args, either with a map or an if, to set your variable name to
> > the matching value in "&?param-name=([^&]*)".
> >
> > But it might be less work to change the input to restrict itself to
> > nginx-friendly characters.
> >
> >         f
> > --
> > Francis Daly        francis at daoine.org
> >
> > _______________________________________________
> > nginx mailing list
> > nginx at nginx.org
> > http://mailman.nginx.org/mailman/listinfo/nginx
> >

> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx


-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list