hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeffrey Dever <jsde...@sympatico.ca>
Subject Re: Bug in setRawPath method of URI class
Date Sat, 25 Jan 2003 01:07:11 GMT
This is another great characterization by Armando.  I wish I had time to 
investigate, but I don't.  Can somone please look into this?

Jandalf.

Armando Antón wrote:

>Hi!
>
>i think there is a bug in the setRawPath method when working with relative paths that
does not start with the '/' character
>
>i will write first the code and after that i will try to explain why there is a bug :)
>
>class URI (lines 2692-2701)
>        } else if (_is_rel_path) {
>            int at = indexFirstOf(escapedPath, '/');
>            if (at == 0)
>                throw new URIException(URIException.PARSING, "incorrect path");
>            if (at > 0 && !validate(escapedPath, 0, at, rel_segment) ||
>                    at < 0 && !validate(escapedPath, 0, -1, abs_path))
>                throw new URIException(URIException.ESCAPING,
>                        "escaped relative path not valid");
>            _path = escapedPath;
>        }
>
>when the uri is relative, first it checks if the escapedPath starts with the '/' character
(if true then the path is not relative and an exception is thrown)
>after that, there is a double check:
>1. there is a '/' character and the escapedpath(from the first character to the first
occurrence of the '/' character) is valid (using the rel_segment BitSet)
>2. there is not a '/' character and the escapedpath (all the characters) is valid (using
the abs_path BitSet)
>
>the problem is in the first check because the substring validated ends with the '/' character
and the rel_segment BitSet does not allow that character
>so an exception is thrown
>
>i really does not understand that double check and i have changed it to:
>
>        } else if (_is_rel_path) {
>            int at = indexFirstOf(escapedPath, '/');
>            if (at == 0)
>                throw new URIException(URIException.PARSING, "incorrect path");
>            if (!validate(escapedPath, 0, -1, abs_path))
>                throw new URIException(URIException.ESCAPING,
>                        "escaped relative path not valid");
>            _path = escapedPath;
>        }  
>
>To test this bug you can execute this simple class and an exception will occur
>
>import org.apache.commons.httpclient.URI;
>
>public class TestSetRawPath {
>
>    public static void main(String[] args) throws Exception {
>        char[] _uri = "dir/doc.html".toCharArray();
>        URI uri = new URI(_uri);
>    }
>}
>
>Hope it helps,
>
>Thank you for your great effort,
>
>Armando
> <<URI_v1.22.diff>> 
>  
>
>------------------------------------------------------------------------
>
>--
>To unsubscribe, e-mail:   <mailto:commons-httpclient-dev-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:commons-httpclient-dev-help@jakarta.apache.org>
>


Mime
View raw message