hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Armando Antón <armando.an...@newknow.com>
Subject Bug in setRawPath method of URI class
Date Fri, 24 Jan 2003 09:50:04 GMT
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>> 

Mime
View raw message