Clean URLs with appended parameters  does not work correctly
------------------------------------------------------------

                 Key: STS-731
                 URL: http://www.stripesframework.org/jira/browse/STS-731
             Project: Stripes
          Issue Type: Bug
          Components: ActionBean Dispatching
    Affects Versions: Release 1.5.2
         Environment: Java 1.6.0_11, Apache Tomcat 6.0.16
            Reporter: Alexander Suslov


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()) {

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://www.stripesframework.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to