Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2012-08-03 07:20:58 +0000
committerJan Bartel2012-08-03 07:20:58 +0000
commit3f0756427438dabf481a48a62a94ad4d41b47e79 (patch)
tree8c77ca2cbafad6396b91292ef73d7d02d7cc382c
parentc998abc8bcb248bbf9535aa48a9f74ba46fe0099 (diff)
downloadorg.eclipse.jetty.project-3f0756427438dabf481a48a62a94ad4d41b47e79.tar.gz
org.eclipse.jetty.project-3f0756427438dabf481a48a62a94ad4d41b47e79.tar.xz
org.eclipse.jetty.project-3f0756427438dabf481a48a62a94ad4d41b47e79.zip
379423 Jetty URL Decoding fails for certain international characters
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java49
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java15
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java4
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java11
4 files changed, 71 insertions, 8 deletions
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
index 1acad63d88..64f981651e 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
@@ -581,6 +581,55 @@ public class HttpURI
_utf8b.append(bytes,0,n);
return _utf8b.toString();
}
+
+
+ public String getDecodedPath(String encoding)
+ {
+ if (_path==_param)
+ return null;
+
+ int length = _param-_path;
+ byte[] bytes=null;
+ int n=0;
+
+ for (int i=_path;i<_param;i++)
+ {
+ byte b = _raw[i];
+
+ if (b=='%')
+ {
+ if ((i+2)>=_param)
+ throw new IllegalArgumentException("Bad % encoding: "+this);
+ b=(byte)(0xff&TypeUtil.parseInt(_raw,i+1,2,16));
+ i+=2;
+ }
+ else if (bytes==null)
+ {
+ n++;
+ continue;
+ }
+
+ if (bytes==null)
+ {
+ bytes=new byte[length];
+ System.arraycopy(_raw,_path,bytes,0,n);
+ }
+
+ bytes[n++]=b;
+ }
+
+
+ if (bytes==null)
+ return StringUtil.toString(_raw,_path,_param-_path,encoding);
+
+ return StringUtil.toString(bytes,0,n,encoding);
+ }
+
+
+
+
+
+
public String getPathAndParam()
{
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java
index e4acf78ed2..c86c8b7d18 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java
@@ -437,7 +437,20 @@ public abstract class AbstractHttpConnection extends AbstractConnection
try
{
_uri.getPort();
- info=URIUtil.canonicalPath(_uri.getDecodedPath());
+ String path = null;
+
+ try
+ {
+ path = _uri.getDecodedPath();
+ }
+ catch (Exception e)
+ {
+ LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1");
+ LOG.ignore(e);
+ path = _uri.getDecodedPath(StringUtil.__ISO_8859_1);
+ }
+
+ info=URIUtil.canonicalPath(path);
if (info==null && !_request.getMethod().equals(HttpMethods.CONNECT))
{
if (_uri.getScheme()!=null && _uri.getHost()!=null)
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java
index ef6b5ae432..5af969d85f 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java
@@ -189,12 +189,12 @@ public class HttpConnectionTest
response=connector.getResponses("GET /foo/bar%c0%00 HTTP/1.1\n"+
"Host: localhost\n"+
"\015\012");
- checkContains(response,0,"HTTP/1.1 400");
+ checkContains(response,0,"HTTP/1.1 200"); //now fallback to iso-8859-1
response=connector.getResponses("GET /bad/utf8%c1 HTTP/1.1\n"+
"Host: localhost\n"+
"\015\012");
- checkContains(response,0,"HTTP/1.1 400");
+ checkContains(response,0,"HTTP/1.1 200"); //now fallback to iso-8859-1
}
finally
{
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java
index d75235d40e..fb6d1eff98 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java
@@ -181,10 +181,11 @@ public class HttpURITest
private final String[][] encoding_tests=
{
- /* 0*/ {"/path/info","/path/info"},
- /* 1*/ {"/path/%69nfo","/path/info"},
- /* 2*/ {"http://host/path/%69nfo","/path/info"},
- /* 3*/ {"http://host/path/%69nf%c2%a4","/path/inf\u00a4"},
+ /* 0*/ {"/path/info","/path/info", "UTF-8"},
+ /* 1*/ {"/path/%69nfo","/path/info", "UTF-8"},
+ /* 2*/ {"http://host/path/%69nfo","/path/info", "UTF-8"},
+ /* 3*/ {"http://host/path/%69nf%c2%a4","/path/inf\u00a4", "UTF-8"},
+ /* 4*/ {"http://host/path/%E5", "/path/\u00e5", "ISO-8859-1"}
};
@Test
@@ -195,7 +196,7 @@ public class HttpURITest
for (int t=0;t<encoding_tests.length;t++)
{
uri.parse(encoding_tests[t][0]);
- assertEquals(""+t,encoding_tests[t][1],uri.getDecodedPath());
+ assertEquals(""+t,encoding_tests[t][1],uri.getDecodedPath(encoding_tests[t][2]));
}
}

Back to the top