Evolve, document how the URI path fix works. Fix 302 redirects so they URL encode properly. bump to -1

This commit is contained in:
sponge
2010-12-26 20:45:29 +00:00
parent 923c3d8b4c
commit 965b2611b3
4 changed files with 31 additions and 3 deletions

View File

@ -296,7 +296,13 @@ public class ResourceHandler extends AbstractHttpHandler
log.debug("Redirect to directory/"); log.debug("Redirect to directory/");
String q=request.getQuery(); 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) if (q!=null&&q.length()!=0)
{ {
buf.append('?'); buf.append('?');

View File

@ -570,9 +570,14 @@ public class URI
*/ */
public static StringBuffer encodePath(StringBuffer buf, String path) 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; byte[] b = null;
/* /*
Keep commented out unless you can prove that this does the right thing.
try { try {
b = path.getBytes(__CHARSET); b = path.getBytes(__CHARSET);
} catch(UnsupportedEncodingException ex) { } catch(UnsupportedEncodingException ex) {
@ -604,12 +609,16 @@ public class URI
char c = _path.charAt(i); char c = _path.charAt(i);
String cs = "" + c; String cs = "" + c;
if(reserved.contains(cs) || !unreserved.contains(cs)) { if(reserved.contains(cs) || !unreserved.contains(cs)) {
/*
We are already bytes
if((c & 0xff) == c) { if((c & 0xff) == c) {
buf.append(gethex(c & 0xff)); buf.append(gethex(c & 0xff));
} else { } else {
buf.append(gethex((c >> 8) & 0xff)); buf.append(gethex((c >> 8) & 0xff));
buf.append(gethex(c & 0xff)); buf.append(gethex(c & 0xff));
} }
*/
buf.append(gethex(c & 0xff));
} else { } else {
buf.append(c); buf.append(c);
} }
@ -717,6 +726,7 @@ public class URI
return path; return path;
/* /*
Keep commented out unless you can prove that this does the right thing.
try try
{ {
return new String(bytes,0,n,__CHARSET); return new String(bytes,0,n,__CHARSET);
@ -752,6 +762,11 @@ public class URI
/** Add two URI path segments. /** Add two URI path segments.
* Handles null and empty paths, path and query params (eg ?a=b or * Handles null and empty paths, path and query params (eg ?a=b or
* ;JSESSIONID=xxx) and avoids duplicate '/' * ;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 p1 URI path segment
* @param p2 URI path segment * @param p2 URI path segment
* @return Legally combined path segments. * @return Legally combined path segments.

View File

@ -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-22 0.8.2 released
2010-12-13 dr|z3d 2010-12-13 dr|z3d

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 0; public final static long BUILD = 1;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";