Author: bombe
Date: 2006-08-10 18:39:02 +0000 (Thu, 10 Aug 2006)
New Revision: 10032
Modified:
trunk/freenet/src/freenet/clients/http/QueueToadlet.java
trunk/freenet/src/freenet/support/URLDecoder.java
Log:
urldecoder now decodes the utf-8 sent by the browser correctly
fix not being able to remove requests with special characters from the queue
page
Modified: trunk/freenet/src/freenet/clients/http/QueueToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/QueueToadlet.java 2006-08-10
18:35:53 UTC (rev 10031)
+++ trunk/freenet/src/freenet/clients/http/QueueToadlet.java 2006-08-10
18:39:02 UTC (rev 10032)
@@ -24,8 +24,6 @@
import freenet.node.fcp.FCPServer;
import freenet.node.fcp.IdentifierCollisionException;
import freenet.node.fcp.MessageInvalidException;
-import freenet.support.HTMLDecoder;
-import freenet.support.HTMLEncoder;
import freenet.support.HTMLNode;
import freenet.support.Logger;
import freenet.support.MultiValueTable;
@@ -82,12 +80,12 @@
}
if(request.isParameterSet("remove_request") &&
(request.getParam("remove_request").length() > 0)) {
- String identifier =
HTMLDecoder.decode(request.getParam("identifier"));
+ String identifier =
request.getParam("identifier");
Logger.minor(this, "Removing "+identifier);
try {
fcp.removeGlobalRequest(identifier);
} catch (MessageInvalidException e) {
- this.sendErrorPage(ctx, 200, "Failed to
remove request", "Failed to remove "+HTMLEncoder.encode(identifier)+" :
"+HTMLEncoder.encode(e.getMessage()));
+ this.sendErrorPage(ctx, 200, "Failed to
remove request", "Failed to remove " + identifier + ": " + e.getMessage());
}
writePermanentRedirect(ctx, "Done", "/queue/");
return;
@@ -97,12 +95,12 @@
Logger.minor(this, "Request count:
"+reqs.length);
for(int i=0; i<reqs.length ; i++){
- String identifier =
HTMLDecoder.decode(reqs[i].getIdentifier());
+ String identifier =
reqs[i].getIdentifier();
Logger.minor(this, "Removing
"+identifier);
try {
fcp.removeGlobalRequest(identifier);
} catch (MessageInvalidException e) {
- this.sendErrorPage(ctx, 200,
"Failed to remove request", "Failed to remove
"+HTMLEncoder.encode(identifier)+" : "+HTMLEncoder.encode(e.getMessage()));
+ this.sendErrorPage(ctx, 200,
"Failed to remove request", "Failed to remove " + identifier + ": " +
e.getMessage());
}
}
writePermanentRedirect(ctx, "Done", "/queue/");
@@ -119,7 +117,7 @@
}
FreenetURI fetchURI;
try {
- fetchURI = new
FreenetURI(HTMLDecoder.decode(request.getParam("key")));
+ fetchURI = new
FreenetURI(request.getParam("key"));
} catch (MalformedURLException e) {
writeError("Invalid URI to download",
"The URI is invalid and can not be downloaded.", ctx);
return;
@@ -130,7 +128,7 @@
writePermanentRedirect(ctx, "Done", "/queue/");
return;
} else if (request.isParameterSet("change_priority")) {
- String identifier =
HTMLDecoder.decode(request.getParam("identifier"));
+ String identifier =
request.getParam("identifier");
short newPriority =
Short.parseShort(request.getParam("priority"));
ClientRequest[] clientRequests =
fcp.getGlobalRequests();
for (int requestIndex = 0, requestCount =
clientRequests.length; requestIndex < requestCount; requestIndex++) {
@@ -148,7 +146,7 @@
insertURI = new FreenetURI("CHK@");
} else if ("ksk".equals(keyType)) {
try {
- insertURI = new
FreenetURI(HTMLDecoder.decode(request.getPartAsString("key", 128)));
+ insertURI = new
FreenetURI(request.getPartAsString("key", 128));
} catch (MalformedURLException mue1) {
writeError("Invalid URI to
insert", "You did not specify a valid URI to insert the file to.", ctx);
return;
@@ -178,10 +176,6 @@
return;
} else if (request.isParameterSet("insert-local")) {
String filename = request.getParam("filename");
- try {
- filename = new
String(filename.getBytes("ISO-8859-1"), "UTF-8");
- } catch (Throwable t) {
- }
File file = new File(filename);
String identifier = file.getName() + "-fred-" +
System.currentTimeMillis();
String contentType =
DefaultMIMETypes.guessMIMEType(filename);
Modified: trunk/freenet/src/freenet/support/URLDecoder.java
===================================================================
--- trunk/freenet/src/freenet/support/URLDecoder.java 2006-08-10 18:35:53 UTC
(rev 10031)
+++ trunk/freenet/src/freenet/support/URLDecoder.java 2006-08-10 18:39:02 UTC
(rev 10032)
@@ -1,5 +1,8 @@
package freenet.support;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
/*
This code is part of the Java Adaptive Network Client by Ian Clarke.
It is distributed under the GNU Public Licence (GPL) version 2. See
@@ -47,51 +50,55 @@
private static final String safeCharList = "$-_.+!*'(),";
/**
- * Translates a string out of x-www-form-urlencoded format.
- *
- * @param s String to be translated.
- * @return the translated String.
- *
- **/
- public static String decode(String s) throws URLEncodedFormatException {
- if (s.length()==0) return "";
- int len = s.length();
- StringBuffer buf = new StringBuffer();
+ * Translates a string out of x-www-form-urlencoded format.
+ *
+ * @param s String to be translated.
+ * @return the translated String.
+ *
+ **/
+ public static String decode(String s) throws URLEncodedFormatException {
+ if (s.length() == 0)
+ return "";
+ int len = s.length();
+ ByteArrayOutputStream decodedBytes = new
ByteArrayOutputStream();
- for (int i = 0; i < len; i++) {
- char c = s.charAt(i);
- if (Character.isLetterOrDigit(c))
- buf.append(c);
- else if (c == '+')
- buf.append(' ');
- else if (safeCharList.indexOf(c) != -1)
- buf.append(c);
- else if (c == '%') {
- if (i >= len - 2) {
- throw new URLEncodedFormatException(s);
- } else {
- char[] hexChars = new char[2];
+ for (int i = 0; i < len; i++) {
+ char c = s.charAt(i);
+ if (Character.isLetterOrDigit(c))
+ decodedBytes.write(c);
+ else if (c == '+')
+ decodedBytes.write(' ');
+ else if (safeCharList.indexOf(c) != -1)
+ decodedBytes.write(c);
+ else if (c == '%') {
+ if (i >= len - 2) {
+ throw new URLEncodedFormatException(s);
+ }
+ char[] hexChars = new char[2];
- hexChars[0] = s.charAt(++i);
- hexChars[1] = s.charAt(++i);
+ hexChars[0] = s.charAt(++i);
+ hexChars[1] = s.charAt(++i);
- String hexval = new String(hexChars);
- try {
- long read = Fields.hexToLong(hexval);
- if (read == 0)
- throw new URLEncodedFormatException("Can't encode"
- + " 00");
- buf.append(new Character((char) read));
- }
- catch (NumberFormatException nfe) {
- throw new URLEncodedFormatException(s);
- }
+ String hexval = new String(hexChars);
+ try {
+ long read = Fields.hexToLong(hexval);
+ if (read == 0)
+ throw new
URLEncodedFormatException("Can't encode" + " 00");
+ decodedBytes.write((int) read);
+ } catch (NumberFormatException nfe) {
+ throw new URLEncodedFormatException(s);
+ }
+ } else
+ decodedBytes.write(c);
+ // throw new URLEncodedFormatException(s);
}
- }
- else
- buf.append(c);
- // throw new URLEncodedFormatException(s);
+ try {
+ decodedBytes.close();
+ return new String(decodedBytes.toByteArray(), "utf-8");
+ } catch (IOException ioe1) {
+ /* if this throws something's wrong */
+ }
+ throw new URLEncodedFormatException(s);
}
- return buf.toString();
- }
+
}