Encoding Ampersand in URL filter

180 views
Skip to first unread message

Ravi

unread,
May 30, 2010, 10:45:28 AM5/30/10
to UrlRewrite
Hello Friends,

I have a URL which contains Ampersand(&) which is encoded as %26 in
query,
Example URL: http://localhost:8888/charts/AREVAT%26D

Rule what I have written urlfilter.xml

<rule>
<from>^/charts/([A-Z0-9&amp;A-Z0-9]+)</from>
<to>/charts?symbol=$1</to>
</rule>

This rule is working fine for all the urls which doesn't contain %26
like http://localhost:8888/charts/abb
When there is encoded ampersand & (i.e %26) the rule is skipping
second part of the query string.
Ex: http://localhost:8888/charts/AREVAT%26D
In the above URL I am getting first part of the query, i.e
AREVAT and %26D is skipped.

I was expecting something like /charts?symbol=AREVAT%26D

Could you please let me know where I have gone wrong.

Thanks,
Ravi

Avlesh Singh

unread,
May 30, 2010, 11:46:22 PM5/30/10
to urlre...@googlegroups.com
I have long been looking for someone to ask a question on using URF functions ;)
Ah .. first Ravi, on a very different note, your regex doesn't make much sense. [A-Z0-9&amp;A-Z0-9] is obviously not doing what you think it is. It is just a range of characters. Having A-Z on both the sides of the &amp; doesn't mean anything good.

However, the problem is not a regex issue. Your regex is good enough to "match" the incoming URL. The problem is in <to> part of the rule. After matcher's replacement, the forwarded URL reads like this - "/charts?symbol=AREVAT&D" .. Notice the unexpected behavior. And it is rightly so.

The underneath should work fine for your use case:
<rule>
    <from>^/charts/([a-zA-Z0-9&amp;]+)$</from>
    <to>/charts?symbol=${escape:$1}</to>
</rule>

Cheers
Avlesh
http://webklipper.com


--
You received this message because you are subscribed to the Google Groups "UrlRewrite" group.
To post to this group, send email to urlre...@googlegroups.com.
To unsubscribe from this group, send email to urlrewrite+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/urlrewrite?hl=en.


Ravi

unread,
May 31, 2010, 12:22:18 AM5/31/10
to UrlRewrite
Hello Avlesh,
Thanks for your help.
I tried your method, it seems it is not matching the rule.

After I submit from my browser, I get following exception in my
control.

WARNING: /charts/AREVAT%26D
java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(Matcher.java:713)
at java.util.regex.Matcher.replaceAll(Matcher.java:813)
at
org.tuckey.web.filters.urlrewrite.RuleBase.executeBase(RuleBase.java:
184)
at org.tuckey.web.filters.urlrewrite.Rule.execute(Rule.java:74)
at
org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:
135)

I am still not able to find the problem.

Thanks,
Ravi



On May 31, 8:46 am, Avlesh Singh <avl...@gmail.com> wrote:
> I have long been looking for someone to ask a question on using URF
> functions ;)
> Ah .. first Ravi, on a very different note, your regex doesn't make much
> sense. [A-Z0-9&amp;A-Z0-9] is obviously not doing what you think it is. It
> is just a range of characters. Having A-Z on both the sides of the &amp;
> doesn't mean anything good.
>
> However, the problem is not a regex issue. Your regex is good enough to
> "match" the incoming URL. The problem is in <to> part of the rule. After
> matcher's replacement, the forwarded URL reads like this -
> "/charts?symbol=AREVAT*&*D" .. Notice the unexpected behavior. And it is
> rightly so.
>
> The underneath should work fine for your use case:
> <rule>
>     <from>^/charts/([a-zA-Z0-9&amp;]+)$</from>
>     <to>/charts?symbol=*${escape:$1}*</to>
> </rule>
>
> Cheers
> Avleshhttp://webklipper.com
>
>
>
> On Sun, May 30, 2010 at 8:15 PM, Ravi <msr...@gmail.com> wrote:
> > Hello Friends,
>
> > I have a URL which contains Ampersand(&) which is encoded as %26 in
> > query,
> > Example URL:  http://localhost:8888/charts/AREVAT%26D
>
> > Rule what I have written urlfilter.xml
>
> > <rule>
> >        <from>^/charts/([A-Z0-9&amp;A-Z0-9]+)</from>
> >        <to>/charts?symbol=$1</to>
> > </rule>
>
> > This rule is working fine for all the urls which doesn't contain %26
> > likehttp://localhost:8888/charts/abb
> > When there is encoded ampersand & (i.e %26) the rule is skipping
> > second part of the query string.
> > Ex:http://localhost:8888/charts/AREVAT%26D
> >      In the above URL I am getting first part of the query, i.e
> > AREVAT   and %26D is skipped.
>
> > I was expecting something like /charts?symbol=AREVAT%26D
>
> > Could you please let me know where I have gone wrong.
>
> > Thanks,
> > Ravi
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "UrlRewrite" group.
> > To post to this group, send email to urlre...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > urlrewrite+...@googlegroups.com<urlrewrite%2Bunsubscribe@googlegrou ps.com>
> > .

Avlesh Singh

unread,
May 31, 2010, 12:24:30 AM5/31/10
to urlre...@googlegroups.com
Which version of URF are you using, Ravi? Functions, like escape, are a 3.2 feature.

Cheers
Avlesh

To unsubscribe from this group, send email to urlrewrite+...@googlegroups.com.

Ravi

unread,
May 31, 2010, 12:32:42 AM5/31/10
to UrlRewrite
Hi Avlesh,
Yes I am using 3.2 version.

Ravi

Avlesh Singh

unread,
May 31, 2010, 3:58:52 AM5/31/10
to urlre...@googlegroups.com
I am sorry for the delay in response Ravi. I tested the rule with version 3.2 and it works for me.
Can you please check the syntax once more? Please copy-paste the rule and the complete exception stacktrace.

Cheers
Avlesh
http://webklipper.com

To unsubscribe from this group, send email to urlrewrite+...@googlegroups.com.

Ravi

unread,
Jun 4, 2010, 12:49:18 AM6/4/10
to UrlRewrite
Hi Avlesh,

I am sorry for delay to respond you early for your Help.
The solution what you provided is working fine.

http://www.bigpaisa.com/charts/AREVAT%26D

We wasted more than 5 hours for this problem.
Thank you very much.

Regards,
Ravi
www.BigPaisa.com


On May 31, 12:58 pm, Avlesh Singh <avl...@gmail.com> wrote:
> I am sorry for the delay in response Ravi. I tested the rule with version
> 3.2 and it works for me.
> Can you please check the syntax once more? Please copy-paste the rule and
> the complete exception stacktrace.
>
> Cheers
> Avleshhttp://webklipper.com

Avlesh Singh

unread,
Jun 4, 2010, 10:38:35 AM6/4/10
to urlre...@googlegroups.com
Cool. Nice. Welcome. Good luck!

Cheers
Avlesh
http://webklipper.com

To unsubscribe from this group, send email to urlrewrite+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages