You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Armando Antón <ar...@newknow.com> on 2003/01/22 11:25:54 UTC

Bug in URIUtil.getPath

When getting the path, it looks for the first occurrence of the '/' character (after the '//') and the last occurrence of the '?' character.
But that is wrong because it must look for the first occurrence of the '?' character because in a query the '?' character is allowed (you can see it in the RFC2396)

To solve this, only is necessary to change the lines 145-146 of the URIUtil class. Current code:
        if (uri.lastIndexOf("?") > from)
            to = uri.lastIndexOf("?");

new code:
        if (uri.indexOf('?',from)!=-1)
            to = uri.indexOf('?',from);

the same change can be done when looking for the '#' character in the followed lines (but it is not necessary because the '#' character is not allowed as part of a fragment

To can test this i have added new test cases in the TestURIUtil class.

It is strange that the getQuery method works well so when looking for the query part of an uri it works well but the path part fails.

An example of this:

URI: http://www.server.com/path1/path2?query1=string?1&query2=string2
current Path (wrong): /path1/path2?query1=string
real Path: /path1/path2


Armando <<URIUtil.diff>>  <<TestURIUtil.diff>>