Re: Error compiling VCL when using '% in regexp

2010-02-08 Thread Poul-Henning Kamp
In message , N
aama Bamberger writes:

>I get this error:
>
>Invalid hex char in %xx escape
>(input Line 107 Pos 28)
>if (req.url ~ "(.*)%[0-9a-fA-F]$") {
>---###--
>

Try: %25

One of the decisions I had most trouble with, was deciding which
kind of escape-mechanism we wanted for strings in VCL.

In the end I settled for URL-%xx encoding, because I pressume
webmasters know it, and because it avoids a nightmare of back-slashes
in regexps.

I'm not 100% convinced that was the perfect decision...

-- 
Poul-Henning Kamp   | UNIX since Zilog Zeus 3.20
p...@freebsd.org | TCP/IP since RFC 956
FreeBSD committer   | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
___
varnish-misc mailing list
varnish-misc@projects.linpro.no
http://projects.linpro.no/mailman/listinfo/varnish-misc


RE: Error compiling VCL when using '% in regexp

2010-02-09 Thread Naama Bamberger
I already tried using the escaped %25.
The compilation succeeded, but the regexp didn't find a match in the 
problematic URLs:

# If the URL ends with % and one digit (a broken hex value) - remove 
the last 2 characters.
if (req.url ~ "(.*)%25[0-9a-fA-F]$") {
set req.url = regsub(req.url, "(.*)%25[0-9a-fA-F]$", "\1");
}

Thanks for your help, 
Naama

-Original Message-
From: p...@critter.freebsd.dk [mailto:p...@critter.freebsd.dk] On Behalf Of 
Poul-Henning Kamp
Sent: Monday, February 08, 2010 12:53 PM
To: Naama Bamberger
Cc: varnish-misc@projects.linpro.no
Subject: Re: Error compiling VCL when using '% in regexp 

In message , 
Naama Bamberger writes:

>I get this error:
>
>Invalid hex char in %xx escape
>(input Line 107 Pos 28)
>if (req.url ~ "(.*)%[0-9a-fA-F]$") {
>---###--
>

Try: %25

One of the decisions I had most trouble with, was deciding which
kind of escape-mechanism we wanted for strings in VCL.

In the end I settled for URL-%xx encoding, because I pressume
webmasters know it, and because it avoids a nightmare of back-slashes
in regexps.

I'm not 100% convinced that was the perfect decision...

-- 
Poul-Henning Kamp   | UNIX since Zilog Zeus 3.20
p...@freebsd.org | TCP/IP since RFC 956
FreeBSD committer   | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
___
varnish-misc mailing list
varnish-misc@projects.linpro.no
http://projects.linpro.no/mailman/listinfo/varnish-misc


Re: Error compiling VCL when using '% in regexp

2010-02-10 Thread Poul-Henning Kamp
In message , N
aama Bamberger writes:
>I already tried using the escaped %25.
>The compilation succeeded, but the regexp didn't find a match in the 
>problematic URLs:
>
>   # If the URL ends with % and one digit (a broken hex value) - remove 
> the last 2 characters.
>   if (req.url ~ "(.*)%25[0-9a-fA-F]$") {
>   set req.url = regsub(req.url, "(.*)%25[0-9a-fA-F]$", "\1");
>   }

I just whipped up a varnishtest case, and it seems to work in -trunk:

test "random test"

server s1 {
rxreq
expect req.url == "/foo"
txresp
} -start

varnish v1 -vcl+backend {

sub vcl_recv {
if (req.url ~ "(.*)%25[0-9a-fA-F]$") {
set req.url = regsub(req.url, "(.*)%25[0-9a-fA-F]$", 
"\1");
}
}

} -start

client c1 {
txreq -url /foo%a
rxresp
} -run

###  c1   Connect to 127.0.0.1:17621
###  c1   Connected to 127.0.0.1:17621 fd is 9
 c1   txreq| GET /foo%a HTTP/1.1\r\n
 c1   txreq| \r\n
###  c1   rxresp
###  s1   Accepted socket fd is 4
###  s1   rxreq
 s1   rxhdr| GET /foo HTTP/1.1\r\n
 s1   rxhdr| X-Forwarded-For: 127.0.0.1\r\n
 s1   rxhdr| X-Varnish: 1001\r\n
 s1   rxhdr| Host: 127.0.0.1\r\n
 s1   rxhdr| \r\n


-- 
Poul-Henning Kamp   | UNIX since Zilog Zeus 3.20
p...@freebsd.org | TCP/IP since RFC 956
FreeBSD committer   | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
___
varnish-misc mailing list
varnish-misc@projects.linpro.no
http://projects.linpro.no/mailman/listinfo/varnish-misc