diff --git a/apps/jetty/java/src/org/mortbay/http/handler/ResourceHandler.java b/apps/jetty/java/src/org/mortbay/http/handler/ResourceHandler.java index 199bbc025..5515df226 100644 --- a/apps/jetty/java/src/org/mortbay/http/handler/ResourceHandler.java +++ b/apps/jetty/java/src/org/mortbay/http/handler/ResourceHandler.java @@ -296,7 +296,13 @@ public class ResourceHandler extends AbstractHttpHandler log.debug("Redirect to directory/"); String q=request.getQuery(); - StringBuffer buf = URI.encodePath(null, request.getRequestURL().toString()); + + // Properly fix URI + URI urifix = new URI(request.getRequestURL().toString()); + urifix.setPath(urifix.getPath()); + StringBuffer buf = new StringBuffer(urifix.toString()); + urifix = null; + if (q!=null&&q.length()!=0) { buf.append('?'); diff --git a/apps/jetty/java/src/org/mortbay/util/URI.java b/apps/jetty/java/src/org/mortbay/util/URI.java index d5543832b..867ef19f4 100644 --- a/apps/jetty/java/src/org/mortbay/util/URI.java +++ b/apps/jetty/java/src/org/mortbay/util/URI.java @@ -570,9 +570,14 @@ public class URI */ public static StringBuffer encodePath(StringBuffer buf, String path) { - // Convert path to native first. + /* Convert path to native character set not __CHARSET. + * This is important to do this way because the path + * contains *OS specific characters* and __CHARSET could + * be wrong and not encode/decode the path correctly. + */ byte[] b = null; /* + Keep commented out unless you can prove that this does the right thing. try { b = path.getBytes(__CHARSET); } catch(UnsupportedEncodingException ex) { @@ -604,12 +609,16 @@ public class URI char c = _path.charAt(i); String cs = "" + c; if(reserved.contains(cs) || !unreserved.contains(cs)) { + /* + We are already bytes if((c & 0xff) == c) { buf.append(gethex(c & 0xff)); } else { buf.append(gethex((c >> 8) & 0xff)); buf.append(gethex(c & 0xff)); } + */ + buf.append(gethex(c & 0xff)); } else { buf.append(c); } @@ -717,6 +726,7 @@ public class URI return path; /* + Keep commented out unless you can prove that this does the right thing. try { return new String(bytes,0,n,__CHARSET); @@ -752,6 +762,11 @@ public class URI /** Add two URI path segments. * Handles null and empty paths, path and query params (eg ?a=b or * ;JSESSIONID=xxx) and avoids duplicate '/' + * + * WARNING: URI path segments must be encoded properly first! + * Use the encodePath method above BEFORE attaching a path + * that contains characters that need escaping! --Sponge + * * @param p1 URI path segment * @param p2 URI path segment * @return Legally combined path segments. diff --git a/history.txt b/history.txt index dfa017173..dca7220f7 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,10 @@ +2010-12-26 sponge + * URI resource fixes from pre-review time from upstream prior merge + * Evolve URI fixs another step. + * Document how the URI path fix works. + * Fix 302 redirects so they URL encode properly. + * bump to -1 + * 2010-12-22 0.8.2 released 2010-12-13 dr|z3d diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index a411b0099..87e5bffca 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 0; + public final static long BUILD = 1; /** for example "-test" */ public final static String EXTRA = "";