Index: src/java/org/apache/commons/httpclient/HttpURL.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpURL.java,v
retrieving revision 1.17
diff -u -r1.17 HttpURL.java
--- src/java/org/apache/commons/httpclient/HttpURL.java 2 May 2004 15:19:15 -0000 1.17
+++ src/java/org/apache/commons/httpclient/HttpURL.java 30 Sep 2004 08:16:35 -0000
@@ -117,8 +117,7 @@
* @see #getDefaultProtocolCharset
*/
public HttpURL(String host, int port, String path) throws URIException {
- this(null, host, port, path, null, null);
- checkValid();
+ this(null, null, host, port, path, null, null);
}
@@ -135,8 +134,7 @@
public HttpURL(String host, int port, String path, String query)
throws URIException {
- this(null, host, port, path, query, null);
- checkValid();
+ this(null, null, host, port, path, query, null);
}
@@ -152,10 +150,7 @@
public HttpURL(String user, String password, String host)
throws URIException {
- this((user == null) ? null : user
- + ((password == null) ? "" : ':' + password),
- host, -1, null, null, null);
- checkValid();
+ this(user, password, host, -1, null, null, null);
}
@@ -172,10 +167,7 @@
public HttpURL(String user, String password, String host, int port)
throws URIException {
- this((user == null) ? null : user
- + ((password == null) ? "" : ':' + password),
- host, port, null, null, null);
- checkValid();
+ this(user, password, host, port, null, null, null);
}
@@ -193,10 +185,7 @@
public HttpURL(String user, String password, String host, int port,
String path) throws URIException {
- this((user == null) ? null : user
- + ((password == null) ? "" : ':' + password),
- host, port, path, null, null);
- checkValid();
+ this(user, password, host, port, path, null, null);
}
@@ -215,10 +204,7 @@
public HttpURL(String user, String password, String host, int port,
String path, String query) throws URIException {
- this((user == null) ? null : user
- + ((password == null) ? "" : ':' + password),
- host, port, path, query, null);
- checkValid();
+ this(user, password, host, port, path, query, null);
}
@@ -235,15 +221,18 @@
public HttpURL(String host, String path, String query, String fragment)
throws URIException {
- this(null, host, -1, path, query, fragment);
- checkValid();
+ this(null, null, host, -1, path, query, fragment);
}
/**
* Construct a HTTP URL from given components.
+ *
+ * Note: The userinfo format is normally
+ * <username>:<password> where
+ * username and password must both be URL escaped.
*
- * @param userinfo the userinfo string
+ * @param userinfo the userinfo string whose parts are URL escaped
* @param host the host string
* @param path the path string
* @param query the query string
@@ -255,14 +244,17 @@
String fragment) throws URIException {
this(userinfo, host, -1, path, query, fragment);
- checkValid();
}
/**
* Construct a HTTP URL from given components.
*
- * @param userinfo the userinfo string
+ * Note: The userinfo format is normally
+ * <username>:<password> where
+ * username and password must both be URL escaped.
+ *
+ * @param userinfo the userinfo string whose parts are URL escaped
* @param host the host string
* @param port the port number
* @param path the path string
@@ -273,14 +265,17 @@
throws URIException {
this(userinfo, host, port, path, null, null);
- checkValid();
}
/**
* Construct a HTTP URL from given components.
*
- * @param userinfo the userinfo string
+ * Note: The userinfo format is normally
+ * <username>:<password> where
+ * username and password must both be URL escaped.
+ *
+ * @param userinfo the userinfo string whose parts are URL escaped
* @param host the host string
* @param port the port number
* @param path the path string
@@ -292,14 +287,17 @@
String query) throws URIException {
this(userinfo, host, port, path, query, null);
- checkValid();
}
/**
* Construct a HTTP URL from given components.
*
- * @param userinfo the userinfo string
+ * Note: The userinfo format is normally
+ * <username>:<password> where
+ * username and password must both be URL escaped.
+ *
+ * @param userinfo the userinfo string whose parts are URL escaped
* @param host the host string
* @param port the port number
* @param path the path string
@@ -318,7 +316,7 @@
buff.append(_default_scheme);
buff.append("://");
if (userinfo != null) {
- buff.append(URIUtil.encode(userinfo, URI.allowed_userinfo));
+ buff.append(userinfo);
buff.append('@');
}
if (host != null) {
@@ -346,6 +344,35 @@
}
parseUriReference(buff.toString(), true);
checkValid();
+ }
+
+
+ /**
+ * Construct a HTTP URL from given components.
+ *
+ * @param user the user name
+ * @param password his or her password
+ * @param host the host string
+ * @param port the port number
+ * @param path the path string
+ * @param query the query string
+ * @param fragment the fragment string
+ * @throws URIException If {@link #checkValid()} fails
+ * @see #getDefaultProtocolCharset
+ */
+ public HttpURL(String user, String password, String host, int port,
+ String path, String query, String fragment) throws URIException {
+ this(toUserinfo(user, password), host, port, path, query, fragment);
+ }
+
+ protected static String toUserinfo(String user, String password) throws URIException {
+ if (user == null) return null;
+ StringBuffer usrinfo = new StringBuffer(20); //sufficient for real world
+ usrinfo.append(URIUtil.encode(user, URI.allowed_within_userinfo));
+ if (password == null) return usrinfo.toString();
+ usrinfo.append(':');
+ usrinfo.append(URIUtil.encode(password, URI.allowed_within_userinfo));
+ return usrinfo.toString();
}
Index: src/java/org/apache/commons/httpclient/HttpsURL.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpsURL.java,v
retrieving revision 1.10
diff -u -r1.10 HttpsURL.java
--- src/java/org/apache/commons/httpclient/HttpsURL.java 14 May 2004 09:47:34 -0000 1.10
+++ src/java/org/apache/commons/httpclient/HttpsURL.java 30 Sep 2004 08:16:35 -0000
@@ -120,7 +120,6 @@
*/
public HttpsURL(String host, int port, String path) throws URIException {
this(null, host, port, path, null, null);
- checkValid();
}
@@ -138,7 +137,6 @@
throws URIException {
this(null, host, port, path, query, null);
- checkValid();
}
@@ -154,10 +152,7 @@
public HttpsURL(String user, String password, String host)
throws URIException {
- this((user == null) ? null : user
- + ((password == null) ? "" : ':' + password),
- host, -1, null, null, null);
- checkValid();
+ this(user, password, host, -1, null, null, null);
}
@@ -174,10 +169,7 @@
public HttpsURL(String user, String password, String host, int port)
throws URIException {
- this((user == null) ? null : user
- + ((password == null) ? "" : ':' + password),
- host, port, null, null, null);
- checkValid();
+ this(user, password, host, port, null, null, null);
}
@@ -195,10 +187,7 @@
public HttpsURL(String user, String password, String host, int port,
String path) throws URIException {
- this((user == null) ? null : user
- + ((password == null) ? "" : ':' + password),
- host, port, path, null, null);
- checkValid();
+ this(user, password, host, port, path, null, null);
}
@@ -217,10 +206,7 @@
public HttpsURL(String user, String password, String host, int port,
String path, String query) throws URIException {
- this((user == null) ? null : user
- + ((password == null) ? "" : ':' + password),
- host, port, path, query, null);
- checkValid();
+ this(user, password, host, port, path, query, null);
}
@@ -238,14 +224,17 @@
throws URIException {
this(null, host, -1, path, query, fragment);
- checkValid();
}
/**
* Construct a HTTPS URL from given components.
*
- * @param userinfo the userinfo string
+ * Note: The userinfo format is normally
+ * <username>:<password> where
+ * username and password must both be URL escaped.
+ *
+ * @param userinfo the userinfo string whose parts are URL escaped
* @param host the host string
* @param path the path string
* @param query the query string
@@ -257,14 +246,17 @@
String fragment) throws URIException {
this(userinfo, host, -1, path, query, fragment);
- checkValid();
}
/**
* Construct a HTTPS URL from given components.
*
- * @param userinfo the userinfo string
+ * Note: The userinfo format is normally
+ * <username>:<password> where
+ * username and password must both be URL escaped.
+ *
+ * @param userinfo the userinfo string whose parts are URL escaped
* @param host the host string
* @param port the port number
* @param path the path string
@@ -275,14 +267,17 @@
throws URIException {
this(userinfo, host, port, path, null, null);
- checkValid();
}
/**
* Construct a HTTPS URL from given components.
*
- * @param userinfo the userinfo string
+ * Note: The userinfo format is normally
+ * <username>:<password> where
+ * username and password must both be URL escaped.
+ *
+ * @param userinfo the userinfo string whose parts are URL escaped
* @param host the host string
* @param port the port number
* @param path the path string
@@ -294,14 +289,17 @@
String query) throws URIException {
this(userinfo, host, port, path, query, null);
- checkValid();
}
/**
* Construct a HTTPS URL from given components.
*
- * @param userinfo the userinfo string
+ * Note: The userinfo format is normally
+ * <username>:<password> where
+ * username and password must both be URL escaped.
+ *
+ * @param userinfo the userinfo string whose parts are URL escaped
* @param host the host string
* @param port the port number
* @param path the path string
@@ -320,7 +318,7 @@
buff.append(_default_scheme);
buff.append("://");
if (userinfo != null) {
- buff.append(URIUtil.encode(userinfo, URI.allowed_userinfo));
+ buff.append(userinfo);
buff.append('@');
}
if (host != null) {
@@ -350,6 +348,23 @@
checkValid();
}
+ /**
+ * Construct a HTTP URL from given components.
+ *
+ * @param user the user name
+ * @param password his or her password
+ * @param host the host string
+ * @param port the port number
+ * @param path the path string
+ * @param query the query string
+ * @param fragment the fragment string
+ * @throws URIException If {@link #checkValid()} fails
+ * @see #getDefaultProtocolCharset
+ */
+ public HttpsURL(String user, String password, String host, int port,
+ String path, String query, String fragment) throws URIException {
+ this(HttpURL.toUserinfo(user, password), host, port, path, query, fragment);
+ }
/**
* Construct a HTTPS URL with a given relative HTTPS URL string.
Index: src/test/org/apache/commons/httpclient/TestURI.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestURI.java,v
retrieving revision 1.11
diff -u -r1.11 TestURI.java
--- src/test/org/apache/commons/httpclient/TestURI.java 14 May 2004 09:47:34 -0000 1.11
+++ src/test/org/apache/commons/httpclient/TestURI.java 30 Sep 2004 08:16:35 -0000
@@ -188,11 +188,16 @@
assertEquals("http://localhost/", url.toString());
assertEquals("user:password@localhost", url.getAuthority());
- url = new HttpURL("user", "pass#", "localhost", 8080, "/");
+ url = new HttpURL("user#@", "pass#@", "localhost", 8080, "/");
assertEquals("http://localhost:8080/", url.toString());
- assertEquals("user:pass#", url.getUserinfo());
- assertEquals("user:pass%23", url.getEscapedUserinfo());
+ assertEquals("user#@:pass#@", url.getUserinfo());
+ assertEquals("user%23%40:pass%23%40", url.getEscapedUserinfo());
+ url = new HttpURL("user%23%40:pass%23%40", "localhost", 8080, "/");
+ assertEquals("http://localhost:8080/", url.toString());
+ assertEquals("user#@:pass#@", url.getUserinfo());
+ assertEquals("user%23%40:pass%23%40", url.getEscapedUserinfo());
+
url = new HttpURL("localhost", 8080, "/");
assertEquals("http://localhost:8080/", url.toString());
url.setRawUserinfo("user".toCharArray(), "password".toCharArray());
@@ -207,10 +212,15 @@
assertEquals("https://localhost/", url.toString());
assertEquals("user:password@localhost", url.getAuthority());
- url = new HttpsURL("user", "pass#", "localhost", 8080, "/");
+ url = new HttpsURL("user#@", "pass#@", "localhost", 8080, "/");
+ assertEquals("https://localhost:8080/", url.toString());
+ assertEquals("user#@:pass#@", url.getUserinfo());
+ assertEquals("user%23%40:pass%23%40", url.getEscapedUserinfo());
+
+ url = new HttpsURL("user%23%40:pass%23%40", "localhost", 8080, "/");
assertEquals("https://localhost:8080/", url.toString());
- assertEquals("user:pass#", url.getUserinfo());
- assertEquals("user:pass%23", url.getEscapedUserinfo());
+ assertEquals("user#@:pass#@", url.getUserinfo());
+ assertEquals("user%23%40:pass%23%40", url.getEscapedUserinfo());
url = new HttpsURL("localhost", 8080, "/");
assertEquals("https://localhost:8080/", url.toString());
Index: .settings/org.eclipse.core.resources.prefs
===================================================================
RCS file: .settings/org.eclipse.core.resources.prefs
diff -N .settings/org.eclipse.core.resources.prefs
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ .settings/org.eclipse.core.resources.prefs 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,3 @@
+#Wed Sep 22 09:49:57 CEST 2004
+encoding/project.xml=ISO-8859-1
+eclipse.preferences.version=1