Index: src/java/org/apache/commons/httpclient/HttpURL.java =================================================================== retrieving revision 1.12.2.3 diff -u -r1.12.2.3 HttpURL.java --- src/java/org/apache/commons/httpclient/HttpURL.java 22 Feb 2004 18:21:13 -0000 1.12.2.3 +++ src/java/org/apache/commons/httpclient/HttpURL.java 1 May 2004 22:21:19 -0000 @@ -31,6 +31,8 @@ package org.apache.commons.httpclient; +import org.apache.commons.httpclient.util.URIUtil; + /** * The HTTP URL. * @@ -318,11 +320,11 @@ buff.append(_default_scheme); buff.append("://"); if (userinfo != null) { - buff.append(userinfo); + buff.append(URIUtil.encode(userinfo, URI.allowed_userinfo)); buff.append('@'); } if (host != null) { - buff.append(host); + buff.append(URIUtil.encode(host, URI.allowed_host)); if (port != -1 || port != DEFAULT_PORT) { buff.append(':'); buff.append(port); @@ -334,17 +336,17 @@ throw new URIException(URIException.PARSING, "abs_path requested"); } - buff.append(path); + buff.append(URIUtil.encode(path, URI.allowed_abs_path)); } if (query != null) { buff.append('?'); - buff.append(query); + buff.append(URIUtil.encode(query, URI.allowed_query)); } if (fragment != null) { buff.append('#'); - buff.append(fragment); + buff.append(URIUtil.encode(fragment, URI.allowed_fragment)); } - parseUriReference(buff.toString(), false); + parseUriReference(buff.toString(), true); checkValid(); } Index: src/test/org/apache/commons/httpclient/TestURI.java =================================================================== retrieving revision 1.4.2.4 diff -u -r1.4.2.4 TestURI.java --- src/test/org/apache/commons/httpclient/TestURI.java 22 Feb 2004 18:21:16 -0000 1.4.2.4 +++ src/test/org/apache/commons/httpclient/TestURI.java 1 May 2004 22:21:20 -0000 @@ -181,14 +181,18 @@ } - public void testTestHttpUrlAuthorityString() throws Exception { HttpURL url = new HttpURL("localhost", -1, "/"); assertEquals("http://localhost/", url.toString()); url.setRawUserinfo("user".toCharArray(), "password".toCharArray()); assertEquals("http://localhost/", url.toString()); assertEquals("user:password@localhost", url.getAuthority()); - + + url = new HttpURL("user", "pass#", "localhost", 8080, "/"); + assertEquals("http://localhost:8080/", url.toString()); + assertEquals("user:pass#", url.getUserinfo()); + assertEquals("user:pass%23", url.getEscapedUserinfo()); + url = new HttpURL("localhost", 8080, "/"); assertEquals("http://localhost:8080/", url.toString()); url.setRawUserinfo("user".toCharArray(), "password".toCharArray());