Author: toad
Date: 2007-08-21 00:42:02 +0000 (Tue, 21 Aug 2007)
New Revision: 14819
Modified:
trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
trunk/freenet/src/freenet/clients/http/LocalFileInsertToadlet.java
trunk/freenet/src/freenet/config/StringArrOption.java
trunk/freenet/src/freenet/support/URLEncoder.java
trunk/freenet/test/freenet/support/URLEncoderDecoderTest.java
Log:
Always specify ascii parameter when encoding URIs.
Always encode to ascii form for HTTP headers, to unicode-friendly form for
generated pages (which are after all UTF-8).
Modified: trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
2007-08-21 00:11:48 UTC (rev 14818)
+++ trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
2007-08-21 00:42:02 UTC (rev 14819)
@@ -56,7 +56,7 @@
for(int i = 0; i < items.size(); i++) {
- String itemPath = URLEncoder.encode(path +
items.get(i).getName());
+ String itemPath = URLEncoder.encode(path +
items.get(i).getName(), false);
HTMLNode li = new HTMLNode("li", "class", "item" ,
items.get(i).getName());
HTMLNode actions = new HTMLNode("span", "class",
"actions");
@@ -80,7 +80,7 @@
BookmarkCategories cats = cat.getSubCategories();
for(int i = 0; i < cats.size(); i++) {
- String catPath = URLEncoder.encode(path +
cats.get(i).getName() + "/");
+ String catPath = URLEncoder.encode(path +
cats.get(i).getName() + "/", false);
HTMLNode subCat = list.addChild("li", "class", "cat",
cats.get(i).getName());
Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2007-08-21
00:11:48 UTC (rev 14818)
+++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2007-08-21
00:42:02 UTC (rev 14819)
@@ -359,7 +359,7 @@
return;
}
String requestedMimeType = httprequest.getParam("type", null);
- String override = (requestedMimeType == null) ? "" :
"?type="+URLEncoder.encode(requestedMimeType);
+ String override = (requestedMimeType == null) ? "" :
"?type="+URLEncoder.encode(requestedMimeType,true);
try {
if(Logger.shouldLog(Logger.MINOR, this))
Logger.minor(this, "FProxy fetching "+key+"
("+maxSize+ ')');
@@ -512,7 +512,7 @@
sb.append(uri.toACIIString());
char c = '?';
if(requestedMimeType != null) {
-
sb.append(c).append("type=").append(URLEncoder.encode(requestedMimeType)); c =
'&';
+
sb.append(c).append("type=").append(URLEncoder.encode(requestedMimeType,false));
c = '&';
}
if(maxSize > 0) {
sb.append(c).append("max-size=").append(maxSize); c =
'&';
Modified: trunk/freenet/src/freenet/clients/http/LocalFileInsertToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/LocalFileInsertToadlet.java
2007-08-21 00:11:48 UTC (rev 14818)
+++ trunk/freenet/src/freenet/clients/http/LocalFileInsertToadlet.java
2007-08-21 00:42:02 UTC (rev 14819)
@@ -44,7 +44,7 @@
if (currentPath == null) {
currentPath = new
File(System.getProperty("user.home"));
}
- writePermanentRedirect(toadletContext, "Found",
"?path=" + URLEncoder.encode(currentPath.getAbsolutePath()));
+ writePermanentRedirect(toadletContext, "Found",
"?path=" + URLEncoder.encode(currentPath.getAbsolutePath(),true));
return;
}
@@ -94,7 +94,7 @@
HTMLNode rootRow = listingTable.addChild("tr");
rootRow.addChild("td");
HTMLNode rootLinkCellNode =
rootRow.addChild("td");
- rootLinkCellNode.addChild("a", "href", "?path="
+ URLEncoder.encode(currentRoot.getCanonicalPath()),
currentRoot.getCanonicalPath());
+ rootLinkCellNode.addChild("a", "href", "?path="
+ URLEncoder.encode(currentRoot.getCanonicalPath(),false),
currentRoot.getCanonicalPath());
rootRow.addChild("td");
}
/* add back link */
@@ -102,7 +102,7 @@
HTMLNode backlinkRow =
listingTable.addChild("tr");
backlinkRow.addChild("td");
HTMLNode backlinkCellNode =
backlinkRow.addChild("td");
- backlinkCellNode.addChild("a", "href", "?path="
+ URLEncoder.encode(currentPath.getParent()), "..");
+ backlinkCellNode.addChild("a", "href", "?path="
+ URLEncoder.encode(currentPath.getParent(),false), "..");
backlinkRow.addChild("td");
}
for (int fileIndex = 0, fileCount = files.length;
fileIndex < fileCount; fileIndex++) {
@@ -112,7 +112,7 @@
fileRow.addChild("td");
if (currentFile.canRead()) {
HTMLNode directoryCellNode =
fileRow.addChild("td");
- directoryCellNode.addChild("a",
"href", "?path=" + URLEncoder.encode(currentFile.getAbsolutePath()),
currentFile.getName());
+ directoryCellNode.addChild("a",
"href", "?path=" + URLEncoder.encode(currentFile.getAbsolutePath(),false),
currentFile.getName());
} else {
fileRow.addChild("td", "class",
"unreadable-file", currentFile.getName());
}
Modified: trunk/freenet/src/freenet/config/StringArrOption.java
===================================================================
--- trunk/freenet/src/freenet/config/StringArrOption.java 2007-08-21
00:11:48 UTC (rev 14818)
+++ trunk/freenet/src/freenet/config/StringArrOption.java 2007-08-21
00:42:02 UTC (rev 14819)
@@ -87,7 +87,7 @@
if(val.length() == 0)
sb.append(":").append(delimiter);
else
-
sb.append(URLEncoder.encode(arr[i])).append(delimiter);
+
sb.append(URLEncoder.encode(arr[i],false)).append(delimiter);
}
if(sb.length() > 0) sb.setLength(sb.length()-1); // drop
surplus delimiter
return sb.toString();
Modified: trunk/freenet/src/freenet/support/URLEncoder.java
===================================================================
--- trunk/freenet/src/freenet/support/URLEncoder.java 2007-08-21 00:11:48 UTC
(rev 14818)
+++ trunk/freenet/src/freenet/support/URLEncoder.java 2007-08-21 00:42:02 UTC
(rev 14819)
@@ -19,7 +19,9 @@
*
* @param URL String to encode
* @param force List of characters (in the form of a string) which must
be encoded as well as the built-in.
- * @return HTML-safe version of string
+ * @param ascii If true, encode all foreign letters, if false, leave
them as is. Set to true if you are
+ * passing to something that needs ASCII (e.g. HTTP headers), set to
false if you are using in an HTML page.
+ * @return Encoded version of string
*/
public final static String encode(String URL, String force, boolean
ascii) {
StringBuffer enc = new StringBuffer(URL.length());
@@ -48,7 +50,15 @@
return enc.toString();
}
- public static String encode(String s) {
+ /**
+ * Encode a string for inclusion in a URI.
+ *
+ * @param URL String to encode
+ * @param ascii If true, encode all foreign letters, if false, leave
them as is. Set to true if you are
+ * passing to something that needs ASCII (e.g. HTTP headers), set to
false if you are using in an HTML page.
+ * @return Encoded version of string
+ */
+ public static String encode(String s, boolean ascii) {
return encode(s, null, false);
}
Modified: trunk/freenet/test/freenet/support/URLEncoderDecoderTest.java
===================================================================
--- trunk/freenet/test/freenet/support/URLEncoderDecoderTest.java
2007-08-21 00:11:48 UTC (rev 14818)
+++ trunk/freenet/test/freenet/support/URLEncoderDecoderTest.java
2007-08-21 00:42:02 UTC (rev 14819)
@@ -78,7 +78,7 @@
String[] encoded = new String[toEncode.length];
//encoding
for (int i = 0; i < encoded.length; i++)
- encoded[i] = URLEncoder.encode(toEncode[i]);
+ encoded[i] = URLEncoder.encode(toEncode[i],false);
//decoding
for (int i = 0; i < encoded.length; i++)
retValue &=
(URLDecoder.decode(encoded[i],false)).equals(toEncode[i]);