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/17 11:44:32 UTC

Bug in URI constructor? should i create a new bug?

Hi!

I have a doubt about the URIs constructors (string parameter vs char[] parameter) and i hope someone can help me :)

In the documentacion it sais:
/**
...
 * <b>The expressions for a URI</b>
 * <p><pre>
 * For escaped URI forms
 *  - URI(char[]) // constructor
 *  - char[] getRawXxx() // method
 *  - String getEscapedXxx() // method
 *  - String toString() // method
 * <p>
 * For unescaped URI forms
 *  - URI(String) // constructor
 *  - String getXXX() // method
 * </pre><p>
.. 
**/

So it is supposed to use the string constructor when dealing with unescaped uris and the char[] constructor when dealing with escaped uris (that is the theory)

This is the code:

    public URI(char[] escaped) throws URIException {
        parseUriReference(new String(escaped), true);
    }

    public URI(String original) throws URIException {
        parseUriReference(original, false);
    }

Both constructors use the same method with a boolean to specify if the string parameter is escaped or not. 
In the parseURIReference method that boolean is used when storing the internal all the uri info (_host, _authority, _query, _fragment) except the path that is always encoded (the boolean parameter is not used so the path is not supposed  to be escaped)

Example code where the _query is created using the escaped info:

            _query = (escaped) ? tmp.substring(at + 1, next).toCharArray() :
            encode(tmp.substring(at + 1, next), allowed_query);

But the _path is created using the setPath method that does not use the escaped parameter (this method is only used here so modifying it would not be a problem) and always encodes the path

You can test it with the following code:

import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.util.URIUtil;

public class TestBugURIConstructor {

    public static void main(String[] args) throws Exception {
        String tmp = "http://host/escaped%24path?escaped%24query#escaped%24fragment";
        char[] _escapedURI = tmp.toCharArray(); // escaped uri
        String _unescapedURI = URIUtil.decode(new String(_escapedURI)); // unescaped uri

        System.out.println("EscapedURI:   " + _escapedURI);
        System.out.println("UnEscapedURI: " + _unescapedURI);

        // EscapedURI info
        System.out.println("**** EscapedURI info ****");
        printInfo(new URI(_escapedURI)); // Using the constructor for escaped uris
        // UnEscapedURI info
        System.out.println("**** UnEscapedURI info ****");
        printInfo(new URI(_unescapedURI)); // Using the constructor for unescaped uris

    }

    private static void printInfo(URI uri) throws Exception {
        System.out.println("getPath: " + uri.getPath());
        System.out.println("getQuery: " + uri.getQuery());
        System.out.println("getFragment: " + uri.getFragment());
        System.out.println("getURI: " + uri.getURI());
    }
}

and the results: (this is just an example)

EscapedURI:   http://host/escaped%24path?escaped%24query#escaped%24fragment
UnEscapedURI: http://host/escaped$path?escaped$query#escaped$fragment
**** EscapedURI info ****
getPath: /escaped%24path
getQuery: escaped$query
getFragment: escaped$fragment
getURI: http://host/escaped%24path?escaped$query
**** UnEscapedURI info ****
getPath: /escaped$path
getQuery: escaped$query
getFragment: escaped$fragment
getURI: http://host/escaped$path?escaped$query

you can see that using different constructors then the path is stored different

Armando



Re: Bug in URI constructor? should i create a new bug?

Posted by Sung-Gu <je...@apache.org>.
Hi  Armando Antón,

> > Both constructors use the same method with a boolean to specify if the
string parameter is escaped or not.
> > In the parseURIReference method that boolean is used when storing the
internal all the uri info (_host, _authority, _query, _fragment) except the
path that is always encoded (the boolean parameter is not used so the path
is not supposed  to be escaped)

That's one of two major bugs...
To fix that, setPath method should have its brother methods to deal them...
;)
And the setPath method should be enable to be the 'public' method.
I was to try to fix it a while ago... But I haven't tested and applied...
:(

I'll look into it soon...  Thank you urging me....

Sung-Gu

Re: Bug in URI constructor? should i create a new bug?

Posted by Jeffrey Dever <js...@sympatico.ca>.
Hey Sung-Gu,

Could you have a look at this problem?  Armando has done an excellent 
job reporting and characterizing the issue, which does appear to be a 
genuine problem.

-jsd


Oleg Kalnichevski wrote:

>Jeff,
>
>Any idea if Sung-Gu would be able to look into the problems reported by
>Armando? Currently none of us can really do any maintenance on URI
>related classes (please correct me if it is not the case) as these
>classes have been virtually one man's department. If Sung-Gu can't
>actively support his stuff, somebody needs to take his work over. It's
>kind of bad that Armando has not gotten virtually no attention to his
>problem reports for days
>
>Oleg
>
>
>On Fri, 2003-01-17 at 11:44, Armando Antón wrote:
>  
>
>>Hi!
>>
>>I have a doubt about the URIs constructors (string parameter vs char[] parameter) and i hope someone can help me :)
>>
>>In the documentacion it sais:
>>/**
>>...
>> * <b>The expressions for a URI</b>
>> * <p><pre>
>> * For escaped URI forms
>> *  - URI(char[]) // constructor
>> *  - char[] getRawXxx() // method
>> *  - String getEscapedXxx() // method
>> *  - String toString() // method
>> * <p>
>> * For unescaped URI forms
>> *  - URI(String) // constructor
>> *  - String getXXX() // method
>> * </pre><p>
>>.. 
>>**/
>>
>>So it is supposed to use the string constructor when dealing with unescaped uris and the char[] constructor when dealing with escaped uris (that is the theory)
>>
>>This is the code:
>>
>>    public URI(char[] escaped) throws URIException {
>>        parseUriReference(new String(escaped), true);
>>    }
>>
>>    public URI(String original) throws URIException {
>>        parseUriReference(original, false);
>>    }
>>
>>Both constructors use the same method with a boolean to specify if the string parameter is escaped or not. 
>>In the parseURIReference method that boolean is used when storing the internal all the uri info (_host, _authority, _query, _fragment) except the path that is always encoded (the boolean parameter is not used so the path is not supposed  to be escaped)
>>
>>Example code where the _query is created using the escaped info:
>>
>>            _query = (escaped) ? tmp.substring(at + 1, next).toCharArray() :
>>            encode(tmp.substring(at + 1, next), allowed_query);
>>
>>But the _path is created using the setPath method that does not use the escaped parameter (this method is only used here so modifying it would not be a problem) and always encodes the path
>>
>>You can test it with the following code:
>>
>>import org.apache.commons.httpclient.URI;
>>import org.apache.commons.httpclient.util.URIUtil;
>>
>>public class TestBugURIConstructor {
>>
>>    public static void main(String[] args) throws Exception {
>>        String tmp = "http://host/escaped%24path?escaped%24query#escaped%24fragment";
>>        char[] _escapedURI = tmp.toCharArray(); // escaped uri
>>        String _unescapedURI = URIUtil.decode(new String(_escapedURI)); // unescaped uri
>>
>>        System.out.println("EscapedURI:   " + _escapedURI);
>>        System.out.println("UnEscapedURI: " + _unescapedURI);
>>
>>        // EscapedURI info
>>        System.out.println("**** EscapedURI info ****");
>>        printInfo(new URI(_escapedURI)); // Using the constructor for escaped uris
>>        // UnEscapedURI info
>>        System.out.println("**** UnEscapedURI info ****");
>>        printInfo(new URI(_unescapedURI)); // Using the constructor for unescaped uris
>>
>>    }
>>
>>    private static void printInfo(URI uri) throws Exception {
>>        System.out.println("getPath: " + uri.getPath());
>>        System.out.println("getQuery: " + uri.getQuery());
>>        System.out.println("getFragment: " + uri.getFragment());
>>        System.out.println("getURI: " + uri.getURI());
>>    }
>>}
>>
>>and the results: (this is just an example)
>>
>>EscapedURI:   http://host/escaped%24path?escaped%24query#escaped%24fragment
>>UnEscapedURI: http://host/escaped$path?escaped$query#escaped$fragment
>>**** EscapedURI info ****
>>getPath: /escaped%24path
>>getQuery: escaped$query
>>getFragment: escaped$fragment
>>getURI: http://host/escaped%24path?escaped$query
>>**** UnEscapedURI info ****
>>getPath: /escaped$path
>>getQuery: escaped$query
>>getFragment: escaped$fragment
>>getURI: http://host/escaped$path?escaped$query
>>
>>you can see that using different constructors then the path is stored different
>>
>>Armando
>>
>>
>>
>>--
>>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>    
>>


Re: Bug in URI constructor? should i create a new bug?

Posted by Oleg Kalnichevski <o....@dplanet.ch>.
Jeff,

Any idea if Sung-Gu would be able to look into the problems reported by
Armando? Currently none of us can really do any maintenance on URI
related classes (please correct me if it is not the case) as these
classes have been virtually one man's department. If Sung-Gu can't
actively support his stuff, somebody needs to take his work over. It's
kind of bad that Armando has not gotten virtually no attention to his
problem reports for days

Oleg


On Fri, 2003-01-17 at 11:44, Armando Antón wrote:
> Hi!
> 
> I have a doubt about the URIs constructors (string parameter vs char[] parameter) and i hope someone can help me :)
> 
> In the documentacion it sais:
> /**
> ...
>  * <b>The expressions for a URI</b>
>  * <p><pre>
>  * For escaped URI forms
>  *  - URI(char[]) // constructor
>  *  - char[] getRawXxx() // method
>  *  - String getEscapedXxx() // method
>  *  - String toString() // method
>  * <p>
>  * For unescaped URI forms
>  *  - URI(String) // constructor
>  *  - String getXXX() // method
>  * </pre><p>
> .. 
> **/
> 
> So it is supposed to use the string constructor when dealing with unescaped uris and the char[] constructor when dealing with escaped uris (that is the theory)
> 
> This is the code:
> 
>     public URI(char[] escaped) throws URIException {
>         parseUriReference(new String(escaped), true);
>     }
> 
>     public URI(String original) throws URIException {
>         parseUriReference(original, false);
>     }
> 
> Both constructors use the same method with a boolean to specify if the string parameter is escaped or not. 
> In the parseURIReference method that boolean is used when storing the internal all the uri info (_host, _authority, _query, _fragment) except the path that is always encoded (the boolean parameter is not used so the path is not supposed  to be escaped)
> 
> Example code where the _query is created using the escaped info:
> 
>             _query = (escaped) ? tmp.substring(at + 1, next).toCharArray() :
>             encode(tmp.substring(at + 1, next), allowed_query);
> 
> But the _path is created using the setPath method that does not use the escaped parameter (this method is only used here so modifying it would not be a problem) and always encodes the path
> 
> You can test it with the following code:
> 
> import org.apache.commons.httpclient.URI;
> import org.apache.commons.httpclient.util.URIUtil;
> 
> public class TestBugURIConstructor {
> 
>     public static void main(String[] args) throws Exception {
>         String tmp = "http://host/escaped%24path?escaped%24query#escaped%24fragment";
>         char[] _escapedURI = tmp.toCharArray(); // escaped uri
>         String _unescapedURI = URIUtil.decode(new String(_escapedURI)); // unescaped uri
> 
>         System.out.println("EscapedURI:   " + _escapedURI);
>         System.out.println("UnEscapedURI: " + _unescapedURI);
> 
>         // EscapedURI info
>         System.out.println("**** EscapedURI info ****");
>         printInfo(new URI(_escapedURI)); // Using the constructor for escaped uris
>         // UnEscapedURI info
>         System.out.println("**** UnEscapedURI info ****");
>         printInfo(new URI(_unescapedURI)); // Using the constructor for unescaped uris
> 
>     }
> 
>     private static void printInfo(URI uri) throws Exception {
>         System.out.println("getPath: " + uri.getPath());
>         System.out.println("getQuery: " + uri.getQuery());
>         System.out.println("getFragment: " + uri.getFragment());
>         System.out.println("getURI: " + uri.getURI());
>     }
> }
> 
> and the results: (this is just an example)
> 
> EscapedURI:   http://host/escaped%24path?escaped%24query#escaped%24fragment
> UnEscapedURI: http://host/escaped$path?escaped$query#escaped$fragment
> **** EscapedURI info ****
> getPath: /escaped%24path
> getQuery: escaped$query
> getFragment: escaped$fragment
> getURI: http://host/escaped%24path?escaped$query
> **** UnEscapedURI info ****
> getPath: /escaped$path
> getQuery: escaped$query
> getFragment: escaped$fragment
> getURI: http://host/escaped$path?escaped$query
> 
> you can see that using different constructors then the path is stored different
> 
> Armando
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
Oleg Kalnichevski <ol...@ural.ru>


Re: Bug in URI constructor? should i create a new bug?

Posted by Oleg Kalnichevski <ol...@ural.ru>.
Jeff,

Any idea if Sung-Gu would be able to look into the problems reported by
Armando? Currently none of us can really do any maintenance on URI
related classes (please correct me if it is not the case) as these
classes have been virtually one man's department. If Sung-Gu can't
actively support his stuff, somebody needs to take his work over. It's
kind of bad that Armando has not gotten virtually no attention to his
problem reports for days

Oleg


On Fri, 2003-01-17 at 11:44, Armando Antón wrote:
> Hi!
> 
> I have a doubt about the URIs constructors (string parameter vs char[] parameter) and i hope someone can help me :)
> 
> In the documentacion it sais:
> /**
> ...
>  * <b>The expressions for a URI</b>
>  * <p><pre>
>  * For escaped URI forms
>  *  - URI(char[]) // constructor
>  *  - char[] getRawXxx() // method
>  *  - String getEscapedXxx() // method
>  *  - String toString() // method
>  * <p>
>  * For unescaped URI forms
>  *  - URI(String) // constructor
>  *  - String getXXX() // method
>  * </pre><p>
> .. 
> **/
> 
> So it is supposed to use the string constructor when dealing with unescaped uris and the char[] constructor when dealing with escaped uris (that is the theory)
> 
> This is the code:
> 
>     public URI(char[] escaped) throws URIException {
>         parseUriReference(new String(escaped), true);
>     }
> 
>     public URI(String original) throws URIException {
>         parseUriReference(original, false);
>     }
> 
> Both constructors use the same method with a boolean to specify if the string parameter is escaped or not. 
> In the parseURIReference method that boolean is used when storing the internal all the uri info (_host, _authority, _query, _fragment) except the path that is always encoded (the boolean parameter is not used so the path is not supposed  to be escaped)
> 
> Example code where the _query is created using the escaped info:
> 
>             _query = (escaped) ? tmp.substring(at + 1, next).toCharArray() :
>             encode(tmp.substring(at + 1, next), allowed_query);
> 
> But the _path is created using the setPath method that does not use the escaped parameter (this method is only used here so modifying it would not be a problem) and always encodes the path
> 
> You can test it with the following code:
> 
> import org.apache.commons.httpclient.URI;
> import org.apache.commons.httpclient.util.URIUtil;
> 
> public class TestBugURIConstructor {
> 
>     public static void main(String[] args) throws Exception {
>         String tmp = "http://host/escaped%24path?escaped%24query#escaped%24fragment";
>         char[] _escapedURI = tmp.toCharArray(); // escaped uri
>         String _unescapedURI = URIUtil.decode(new String(_escapedURI)); // unescaped uri
> 
>         System.out.println("EscapedURI:   " + _escapedURI);
>         System.out.println("UnEscapedURI: " + _unescapedURI);
> 
>         // EscapedURI info
>         System.out.println("**** EscapedURI info ****");
>         printInfo(new URI(_escapedURI)); // Using the constructor for escaped uris
>         // UnEscapedURI info
>         System.out.println("**** UnEscapedURI info ****");
>         printInfo(new URI(_unescapedURI)); // Using the constructor for unescaped uris
> 
>     }
> 
>     private static void printInfo(URI uri) throws Exception {
>         System.out.println("getPath: " + uri.getPath());
>         System.out.println("getQuery: " + uri.getQuery());
>         System.out.println("getFragment: " + uri.getFragment());
>         System.out.println("getURI: " + uri.getURI());
>     }
> }
> 
> and the results: (this is just an example)
> 
> EscapedURI:   http://host/escaped%24path?escaped%24query#escaped%24fragment
> UnEscapedURI: http://host/escaped$path?escaped$query#escaped$fragment
> **** EscapedURI info ****
> getPath: /escaped%24path
> getQuery: escaped$query
> getFragment: escaped$fragment
> getURI: http://host/escaped%24path?escaped$query
> **** UnEscapedURI info ****
> getPath: /escaped$path
> getQuery: escaped$query
> getFragment: escaped$fragment
> getURI: http://host/escaped$path?escaped$query
> 
> you can see that using different constructors then the path is stored different
> 
> Armando
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
Oleg Kalnichevski <ol...@ural.ru>