Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: Release 1.5.2
-
Fix Version/s: Release 1.5.4
-
Component/s: ActionBean Dispatching
-
Labels:None
-
Environment:Java 1.6.0_11, Apache Tomcat 6.0.16
Description
I have several action beans that mapped to these URLs:
1) /company/{company}/
2) /company/{company}/gallery/
3) /company/{company}/skills/
4) and so on
Where {company} is a company id or name. It works fine for links like this (for company with name/id test):
http://localhost:8080/web/company/test/
http://localhost:8080/web/company/test/gallery/
http://localhost:8080/web/company/test/skills/
But it is not work for links like this (for company with name/id 1)
http://localhost:8080/web/company/1/
http://localhost:8080/web/company/1/gallery/
http://localhost:8080/web/company/1/skills/
You will ask "what the difference?" And the difference is in the length of parameter in query string. When length is 1 then it not work. If we replace 1 (company id) with 01 then it will work:
http://localhost:8080/web/company/01/
http://localhost:8080/web/company/01/gallery/
http://localhost:8080/web/company/01/skills/
I had study the code of UrlBindingFactory and I think that I had found the bug source. And the bug is in method getBinding(String uri) (line 249 for version 1.5.2). Here is the code fragment from this method:
// ignore trailing slashes in the URI
int length = uri.length();
while (length > 0 && uri.charAt(length - 1) == '/')
--length;
// check for literal suffix in prototype and ignore it if found
String suffix = prototype.getSuffix();
if (suffix != null && uri.endsWith(suffix)) {
length -= suffix.length();
}
...
while (index < length && iter.hasNext()) {
I think that ignore trailing slashes is not correct operation or it mast be after suffix ignoring. Now let's try to see what happens with my mappings with following request http://localhost:8080/web/company/1/:
1) uri = "/company/1/";
2) suffix = "/"
3) Ignore trailing slashes. In general, after that we will process only this part of uri: "/company/1"
4) Ignore prototype suffix. In general, after that we will process only this part of uri: "/company/" which is not correct on my mind.
As you can see we ignore last slash twice which is bad I think.
I think that this part of code needs to be looks like this:
int length = uri.length();
// check for literal suffix in prototype and ignore it if found
String suffix = prototype.getSuffix();
if (suffix != null && uri.endsWith(suffix)) {
length -= suffix.length();
}
// ignore trailing slashes in the URI
while (length > 0 && uri.charAt(length - 1) == '/')
--length;
...
while (index < length && iter.hasNext()) {
I had just check the source code of the 1.5.3 version, and as I can see this bug is steel present in the last version too.