New issue 30 by binarygroop: ":" char in url results in
java.io.UnsupportedEncodingException
http://code.google.com/p/urlrewritefilter/issues/detail?id=30
What steps will reproduce the problem?
1. put ":" character into url that is beeing rewriten
2. the unsupported encoding exception raise immediately
What is the expected output? What do you see instead?
I should get the page with search results
Instead I see this exception:
java.io.UnsupportedEncodingException: dog
at java.net.URLEncoder.encode(URLEncoder.java:200)
at
org.tuckey.web.filters.urlrewrite.functions.StringFunctions.escape(StringFunctions.java:49)
at
org.tuckey.web.filters.urlrewrite.utils.FunctionReplacer.functionReplace(FunctionReplacer.java:118)
at
org.tuckey.web.filters.urlrewrite.utils.FunctionReplacer.replace(FunctionReplacer.java:78)
at
org.tuckey.web.filters.urlrewrite.RuleBase.matchesBase(RuleBase.java:248)
at
org.tuckey.web.filters.urlrewrite.NormalRule.matches(NormalRule.java:91)
at
org.tuckey.web.filters.urlrewrite.RuleChain.doRuleProcessing(RuleChain.java:83)
at
org.tuckey.web.filters.urlrewrite.RuleChain.process(RuleChain.java:137)
at
org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:144)
at
org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
at
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)
What version of the product are you using? On what operating system?
Version 3.2.0 beta on Windows XP
Please provide any additional information below.
It seems that tuckey rewrite is unable to process character: ":". I have a
search page with for example url: http://localhost/search/town:
springfield/in/category. Having this url will result into exception beeing
thrown by tuckey and page is redirected to http://localhost/.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
Seems invalid. An error in the rewrite rule might have led to this. Please
post such
problems on the mailing list first.
Comment #2 on issue 30 by tuckey: ":" char in url results in
java.io.UnsupportedEncodingException
http://code.google.com/p/urlrewritefilter/issues/detail?id=30
Agree, please post exact rule used and debug log so that this can be
investigated
further.
I can confirm this issue. The error occurs, when a parameter contains a
colon. At our
site, for example, we have the following rule for rewriting search queries:
<rule>
<name>redirect /search/SEARCH</name>
<condition type="parameter" name="search">(.+)</condition>
<from>^/+search$</from>
<to type="redirect" last="true">/search/${escape:%1}</to>
</rule>
The following query results in a UnsupportedEncodingException as described
above:
http://<ourhost>/search?search=test:
The reason for this exception is found in StringFunctions.java. If a
parameter
contains a colon (':'), the prefix is treaded as an encoding name:
String encoding = "UTF-8";
if ( FIND_COLON_PATTERN.matcher(subject).find()) {
encoding = subject.substring(0, subject.indexOf(':'));
subject = subject.substring(subject.indexOf(':')+1);
}
I didn't find this feature's documentation and I strongly suggest to
disable it - or
at least make it optional.
I would suggest to set this bug to "open", since this issue is not solved!
It really
breaks functionality: parameter values containing a colon (":") are not
supported.
Does this trigger when you encode the colon? (unencoded colons are not
legal in
parameter names/values)
Please excuse the inaccurate description above - we are encoding the
parameters, that is:
http://<ourhost>/search?search=test%3Atest
produces the error above
+1 for reopening. This really seems like a bug - and not a config issue.
Comment #8 on issue 30 by avlesh: ":" char in url results in
java.io.UnsupportedEncodingException
http://code.google.com/p/urlrewritefilter/issues/detail?id=30
Re-opening the ticket.
Indeed, when you use ${escape:...} the colon is used as an indicator for
encoding.
This syntax supports escaping the colon with a simple '\', but as you can't
seem to
nest functions properly, there seems to be no way to actually make use of
that.
So no real work-around yet except don't use $escape{} and a colon together.
I tend to
agree with the commenters. Would it be acceptable if I submitted a patch
which falls
back to UTF-8 on an UnsupportedEncodingException? I've got it working but
need to do
some more testing. I'll attach it.
Attachments:
encoding_exception.patch 2.7 KB
Thanks kronmagg for the patch. And it was quick too! Falling back on UTF-8
is not a
bad idea. Can you please add/modify test cases to in a revised patch?
I added some tests to FunctionReplacerTest. Note that there was a bug in my
patch. It
seems ${escape} expected a String of the forum "UTF-16:blah" while
${unescape}
expected one of the forum "blah:UTF-16". Not sure why...
Attachments:
enc_patch.txt 4.5 KB
Too soon on the "save changes" button. I changed unescape so they now both
use
"UTF-16:blah" by convention. I'm not entirely convinced anyone actually has
a use for
this feature in either case. AFAICT the only valid encoding you'd ever want
to use in
this scenario is UTF-8.
Comment #13 on issue 30 by avlesh: ":" char in url results in
java.io.UnsupportedEncodingException
http://code.google.com/p/urlrewritefilter/issues/detail?id=30
Changed the status from "invalid". Will shortly review "kromagg's" patch ...
Issue 63 has been merged into this issue.
Comment #15 on issue 30 by tuckey: ":" char in url results in
java.io.UnsupportedEncodingException
http://code.google.com/p/urlrewritefilter/issues/detail?id=30
Thanks. Have applied a slightly modified patch
http://code.google.com/p/urlrewritefilter/source/detail?r=293
This will be in the version 4 release.