Quantcast

Nginx cookie map regex remove + character

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Nginx cookie map regex remove + character

tory
So this is my map

map $http_cookie $session_id_value {
default '';
"~^.*[0-9a-f]{32}\=(?<session_value>[\w]{1,}+).*$" $session_value;
}


The cookie name = a MD5 sum the full / complete value of the cookie seems to
cut of at a plus + symbol

What would the correct regex to be to ignore / remove + symbols from
"session_value"

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273182,273182#msg-273182

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nginx cookie map regex remove + character

Francis Daly
On Fri, Mar 24, 2017 at 05:18:23PM -0400, c0nw0nk wrote:

Hi there,

> The cookie name = a MD5 sum the full / complete value of the cookie seems to
> cut of at a plus + symbol

Your regex piece is

(?<session_value>[\w]{1,}+)

which says to match one or more \w characters ({1,}), one or more times (+)

\w is "word character", which is alnum-or-underscore.

> What would the correct regex to be to ignore / remove + symbols from
> "session_value"

If you want to match "word character or plus", use something like [\w+].

And then also probably remove one of "{1,}" and "+", since they mean
the same thing and having both is redundant.

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nginx cookie map regex remove + character

nginx mailing list
On Sat, Apr 1, 2017 at 1:57 PM, Francis Daly <[hidden email]> wrote:
If you want to match "word character or plus", use something like [\w+].

​Defining a pattern over a simple assertion is kinda strange​. '[' & ']' are useless here, since you are not matching several symbols.
Use (?<session_value>\w+) and you should be all set.

Btw, if you were to use '+', [\w+] and [\w]+ have different meaning: first quantifier applies to '\w' only while latter applies to all the symbols in the pattern.
---
B. R.


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nginx cookie map regex remove + character

Francis Daly
On Mon, Apr 03, 2017 at 10:12:04AM +0200, B.R. via nginx wrote:
> On Sat, Apr 1, 2017 at 1:57 PM, Francis Daly <[hidden email]> wrote:
>
> > If you want to match "word character or plus", use something like [\w+].
> >
>
> ​Defining a pattern over a simple assertion is kinda strange​. '[' & ']'
> are useless here, since you are not matching several symbols.

I think we may be reading the original question differently.

I read it that the current regex matches one or more letter-or-number, and
what is wanted is something to match one or more letter-or-number-or-plus.

> Use (?<session_value>\w+) and you should be all set.
>
> Btw, if you were to use '+', [\w+] and [\w]+ have different meaning: first
> quantifier applies to '\w' only while latter applies to all the symbols in
> the pattern.

The first + is not a quantifier. At least, in the regex engine I use.

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Loading...