Re: Matching of special characters in location

2020-11-10 Thread Francis Daly
On Tue, Nov 10, 2020 at 02:54:26AM +0100, Grzegorz Kulewski wrote:
> W dniu 10.11.2020 o 01:19, Francis Daly pisze:

Hi there,

> > So my config file can include (e.g.)
> > 
> >   location ^~/<200b> { return 200 "match /zwsp ($uri, $request_uri)\n"; }
> > 
> > (except there is only one "character" between the / and the space);
> > and then any request that starts with /%e2%80%8b should be handled in
> > that location; and any request that does not, should not be.
> 
> Including raw UTF-8 special characters in nginx config isn't my ideal sane 
> solution. :)

That's reasonable; but I think I'd disagree.

I'd suggest that if you can't write the character, you probably shouldn't
be using it in your web site such that it is needed in this part of the
config file :-)

> I think I would prefer to be able to use escapes in non-regexp matches too...

That's a reasonable preference. Current stock-nginx does not support it,
as far as I know. But you can add it yourself, if it is important enough.

If you can decide on an escape syntax that you like (and: most will
probably break some current valid config, so you'll want to choose one
that works for you), then you can either try to get the code to handle
it added to nginx; or (more likely, in the short term at least) you can
write a pre-processor for you that turns your nginx.conf.in (with escaped
characters in "location" values that start with something other than ~
or @) into an nginx.conf that includes the un-escaped characters in the
format that current-nginx will read.

Cheers,

f
-- 
Francis Dalyfran...@daoine.org
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: Matching of special characters in location

2020-11-09 Thread Grzegorz Kulewski
W dniu 10.11.2020 o 01:19, Francis Daly pisze:
> On Tue, Nov 10, 2020 at 12:11:28AM +0100, Grzegorz Kulewski wrote:
>> W dniu 09.11.2020 o 21:10, Sergey A. Osokin pisze:
>>> On Mon, Nov 09, 2020 at 03:47:13PM +0100, Grzegorz Kulewski wrote:
 Is there any (sane) way to match things like: %e2%80%8b in URL in location?
> 
>>> here is the code snippet (not tested):
>>>
>>> location ~ ^/\xE2\x80\x8E {
>>> return 200 "%e2%80%8b matched\n"/;
>>> }
>>
>> Thank you. It works.
>>
>> They key seems to be using regexp match. Regular match doesn't seem to 
>> understand escapes. Not sure if (where) it is documented.
> 
> Regex match is straightforward here -- you use whatever your regex-engine
> supports to match the octets, which probably includes a straight swap
> of \x for % from the url.
> 
> Non-regex match does work too, though; the key there is that nginx does
> that match against the non-url-encoded characters.

This is documented.


> In my case, it displays as <200b> and represents a single character.
> 
> So my config file can include (e.g.)
> 
>   location ^~/<200b> { return 200 "match /zwsp ($uri, $request_uri)\n"; }
> 
> (except there is only one "character" between the / and the space);
> and then any request that starts with /%e2%80%8b should be handled in
> that location; and any request that does not, should not be.

Including raw UTF-8 special characters in nginx config isn't my ideal sane 
solution. :)

I think I would prefer to be able to use escapes in non-regexp matches too...

-- 
Grzegorz Kulewski

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: Matching of special characters in location

2020-11-09 Thread Francis Daly
On Tue, Nov 10, 2020 at 12:11:28AM +0100, Grzegorz Kulewski wrote:
> W dniu 09.11.2020 o 21:10, Sergey A. Osokin pisze:
> > On Mon, Nov 09, 2020 at 03:47:13PM +0100, Grzegorz Kulewski wrote:

Hi there,

> >> Is there any (sane) way to match things like: %e2%80%8b in URL in location?

> > here is the code snippet (not tested):
> > 
> > location ~ ^/\xE2\x80\x8E {
> > return 200 "%e2%80%8b matched\n"/;
> > }
> 
> Thank you. It works.
> 
> They key seems to be using regexp match. Regular match doesn't seem to 
> understand escapes. Not sure if (where) it is documented.
> 

Regex match is straightforward here -- you use whatever your regex-engine
supports to match the octets, which probably includes a straight swap
of \x for % from the url.

Non-regex match does work too, though; the key there is that nginx does
that match against the non-url-encoded characters.

%e2%80%8b is the url-encoding of three octets; in a utf-8 world, they
represent the utf-8 encoding of the unicode code point U+200B (ZERO
WIDTH SPACE).

So if you want to prefix-match on a string including that character,
you'll need to include that character directly in your config file. Your
text editor should have some way of letting you do that -- for example,
in "vim" in insert mode, the six-character sequence control-V, u, 2, 0,
0, b will do the right thing.

In my case, it displays as <200b> and represents a single character.

So my config file can include (e.g.)

  location ^~/<200b> { return 200 "match /zwsp ($uri, $request_uri)\n"; }

(except there is only one "character" between the / and the space);
and then any request that starts with /%e2%80%8b should be handled in
that location; and any request that does not, should not be.

Cheers,

f
-- 
Francis Dalyfran...@daoine.org
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: Matching of special characters in location

2020-11-09 Thread Grzegorz Kulewski
W dniu 09.11.2020 o 21:10, Sergey A. Osokin pisze:
> On Mon, Nov 09, 2020 at 03:47:13PM +0100, Grzegorz Kulewski wrote:
>> Hello,
>>
>> Is there any (sane) way to match things like: %e2%80%8b in URL in location?
>> Thank you in advance.
> 
> Hi Grzegorz,
> 
> here is the code snippet (not tested):
> 
> location ~ ^/\xE2\x80\x8E {
> return 200 "%e2%80%8b matched\n"/;
> }

Thank you. It works.

They key seems to be using regexp match. Regular match doesn't seem to 
understand escapes. Not sure if (where) it is documented.

-- 
Grzegorz Kulewski

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: Matching of special characters in location

2020-11-09 Thread Sergey A. Osokin
On Mon, Nov 09, 2020 at 03:47:13PM +0100, Grzegorz Kulewski wrote:
> Hello,
> 
> Is there any (sane) way to match things like: %e2%80%8b in URL in location?
> Thank you in advance.

Hi Grzegorz,

here is the code snippet (not tested):

location ~ ^/\xE2\x80\x8E {
return 200 "%e2%80%8b matched\n"/;
}

--
Sergey
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx