You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2005/04/06 23:46:11 UTC
svn commit: r160334 - in jakarta/commons/proper/httpclient/trunk/src:
java/org/apache/commons/httpclient/HttpMethodBase.java
test/org/apache/commons/httpclient/TestURI.java
Author: olegk
Date: Wed Apr 6 14:46:10 2005
New Revision: 160334
URL: http://svn.apache.org/viewcvs?view=rev&rev=160334
Log:
PR #33720 (method.getURI() returns escaped URIs but it shouldn't)
Contributed by Oleg Kalnichevski
Reviewed by Michael Becke and Ortwin Glück
Modified:
jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java
Modified: jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java?view=diff&r1=160333&r2=160334
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodBase.java Wed Apr 6 14:46:10 2005
@@ -242,32 +242,23 @@
* @see org.apache.commons.httpclient.HttpMethod#getURI()
*/
public URI getURI() throws URIException {
-
- if (this.httphost == null) {
- // just use a relative URI, the host hasn't been set
- URI tmpUri = new URI(null, null, path, null, null);
- tmpUri.setEscapedQuery(queryString);
- return tmpUri;
- } else {
-
- // we only want to include the port if it's not the default
+ StringBuffer buffer = new StringBuffer();
+ if (this.httphost != null) {
+ buffer.append(this.httphost.getProtocol().getScheme());
+ buffer.append("://");
+ buffer.append(this.httphost.getHostName());
int port = this.httphost.getPort();
- if (port == this.httphost.getProtocol().getDefaultPort()) {
- port = -1;
+ if (port != -1 && port != this.httphost.getProtocol().getDefaultPort()) {
+ buffer.append(":");
+ buffer.append(port);
}
- URI tmpUri = new URI(
- this.httphost.getProtocol().getScheme(),
- null,
- this.httphost.getHostName(),
- port,
- path,
- null // to set an escaped form
- );
- tmpUri.setEscapedQuery(queryString);
- return tmpUri;
-
}
-
+ buffer.append(this.path);
+ if (this.queryString != null) {
+ buffer.append('?');
+ buffer.append(this.queryString);
+ }
+ return new URI(buffer.toString(), true);
}
/**
Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java?view=diff&r1=160333&r2=160334
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestURI.java Wed Apr 6 14:46:10 2005
@@ -31,6 +31,8 @@
package org.apache.commons.httpclient;
+import org.apache.commons.httpclient.methods.GetMethod;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -230,4 +232,20 @@
}
+ public void testURIEscaping() throws Exception {
+ String escaped = "http://some.host.com/%41.html";
+ String unescaped = "http://some.host.com/A.html";
+ URI u1 = new URI(escaped, true);
+ GetMethod method = new GetMethod();
+ method.setURI(u1);
+ URI u2 = method.getURI();
+
+ assertEquals(escaped, u1.toString());
+ assertEquals(escaped, new String(u1.getRawURI()));
+ assertEquals(unescaped, u1.getURI());
+ assertEquals(escaped, u2.toString());
+ assertEquals(escaped, new String(u2.getRawURI()));
+ assertEquals(unescaped, u2.getURI());
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org