hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <o...@ural.ru>
Subject Re: Bug in URI constructor? should i create a new bug?
Date Sun, 19 Jan 2003 21:44:29 GMT
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:   <mailto:commons-httpclient-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-httpclient-dev-help@jakarta.apache.org>
-- 
Oleg Kalnichevski <oleg@ural.ru>


Mime
View raw message