")
.append(_("Torrent"))
.append(": ")
- .append(snark.getBaseName())
+ .append(DataHelper.escapeHTML(snark.getBaseName()))
.append(" | \n");
String fullPath = snark.getName();
- String baseName = urlEncode((new File(fullPath)).getName());
+ String baseName = encodePath((new File(fullPath)).getName());
buf.append("
")
.append(" ")
.append(_("Torrent file"))
.append(": ")
- .append(fullPath)
+ .append(DataHelper.escapeHTML(fullPath))
.append(" |
\n");
buf.append("
")
.append(" ")
.append(_("Data location"))
.append(": ")
- .append(urlEncode(snark.getStorage().getBase().getPath()))
+ .append(DataHelper.escapeHTML(snark.getStorage().getBase().getPath()))
.append(" |
\n");
String announce = null;
@@ -2593,7 +2635,7 @@ public class I2PSnarkServlet extends BasicServlet {
.append("\">\n");
buf.append("\n\n");
buf.append("
")
.append(_("Up to higher level directory"))
.append(" |
\n");
@@ -2604,7 +2646,7 @@ public class I2PSnarkServlet extends BasicServlet {
boolean showSaveButton = false;
for (int i=0 ; i< ls.length ; i++)
{
- String encoded = encodePath(ls[i].getName());
+ //String encoded = encodePath(ls[i].getName());
// bugfix for I2P - Backport from Jetty 6 (zero file lengths and last-modified times)
// http://jira.codehaus.org/browse/JETTY-361?page=com.atlassian.jira.plugin.system.issuetabpanels%3Achangehistory-tabpanel#issue-tabs
// See resource.diff attachment
@@ -2653,10 +2695,10 @@ public class I2PSnarkServlet extends BasicServlet {
}
}
- String path=addPaths(base,encoded);
+ String path = addPaths(decodedBase, ls[i].getName());
if (item.isDirectory() && !path.endsWith("/"))
path=addPaths(path,"/");
- path = urlEncode(path);
+ path = encodePath(path);
String icon = toIcon(item);
buf.append("
");
@@ -2677,7 +2719,7 @@ public class I2PSnarkServlet extends BasicServlet {
buf.append(" | ");
if (complete)
buf.append("");
- buf.append(item.getName().replace("&", "&"));
+ buf.append(DataHelper.escapeHTML(item.getName()));
if (complete)
buf.append("");
buf.append(" | ");
@@ -2808,6 +2850,36 @@ public class I2PSnarkServlet extends BasicServlet {
}
}
snark.updatePiecePriorities();
- _manager.saveTorrentStatus(snark.getMetaInfo(), storage.getBitField(), storage.getFilePriorities(), storage.getBase());
+ _manager.saveTorrentStatus(snark);
+ }
+
+ /**
+ * Is "a" equal to "b",
+ * or is "a" a directory and a parent of file or directory "b",
+ * canonically speaking?
+ *
+ * @since 0.9.15
+ */
+ private static boolean isParentOf(File a, File b) {
+ try {
+ a = a.getCanonicalFile();
+ b = b.getCanonicalFile();
+ } catch (IOException ioe) {
+ return false;
+ }
+ if (a.equals(b))
+ return true;
+ if (!a.isDirectory())
+ return false;
+ // easy case
+ if (!b.getPath().startsWith(a.getPath()))
+ return false;
+ // dir by dir
+ while (!a.equals(b)) {
+ b = b.getParentFile();
+ if (b == null)
+ return false;
+ }
+ return true;
}
}
diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/URIUtil.java b/apps/i2psnark/java/src/org/klomp/snark/web/URIUtil.java
new file mode 100644
index 000000000..3a9c3088e
--- /dev/null
+++ b/apps/i2psnark/java/src/org/klomp/snark/web/URIUtil.java
@@ -0,0 +1,206 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.klomp.snark.web;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URLEncoder;
+
+import net.i2p.data.DataHelper;
+
+
+/** URI Holder.
+ * This class assists with the decoding and encoding or HTTP URI's.
+ * It differs from the java.net.URL class as it does not provide
+ * communications ability, but it does assist with query string
+ * formatting.
+ * UTF-8 encoding is used by default for % encoded characters. This
+ * may be overridden with the org.eclipse.jetty.util.URI.charset system property.
+ * see UrlEncoded
+ *
+ * I2P modded from Jetty 8.1.15
+ * @since 0.9.15
+ */
+class URIUtil
+{
+
+ /** Encode a URI path.
+ * This is the same encoding offered by URLEncoder, except that
+ * the '/' character is not encoded.
+ * @param path The path the encode
+ * @return The encoded path
+ */
+ public static String encodePath(String path)
+ {
+ if (path==null || path.length()==0)
+ return path;
+
+ StringBuilder buf = encodePath(null,path);
+ return buf==null?path:buf.toString();
+ }
+
+ /** Encode a URI path.
+ * @param path The path the encode
+ * @param buf StringBuilder to encode path into (or null)
+ * @return The StringBuilder or null if no substitutions required.
+ */
+ public static StringBuilder encodePath(StringBuilder buf, String path)
+ {
+ byte[] bytes=null;
+ if (buf==null)
+ {
+ loop:
+ for (int i=0;i':
+ case ' ':
+ buf=new StringBuilder(path.length()*2);
+ break loop;
+ default:
+ if (c>127)
+ {
+ bytes = DataHelper.getUTF8(path);
+ buf=new StringBuilder(path.length()*2);
+ break loop;
+ }
+
+ }
+ }
+ if (buf==null)
+ return null;
+ }
+
+ //synchronized(buf)
+ //{
+ if (bytes!=null)
+ {
+ for (int i=0;i':
+ buf.append("%3E");
+ continue;
+ case ' ':
+ buf.append("%20");
+ continue;
+ default:
+ if (c<0)
+ {
+ buf.append('%');
+ toHex(c,buf);
+ }
+ else
+ buf.append((char)c);
+ continue;
+ }
+ }
+
+ }
+ else
+ {
+ for (int i=0;i':
+ buf.append("%3E");
+ continue;
+ case ' ':
+ buf.append("%20");
+ continue;
+ default:
+ buf.append(c);
+ continue;
+ }
+ }
+ }
+ //}
+
+ return buf;
+ }
+
+ /**
+ * Modded from Jetty TypeUtil
+ */
+ private static void toHex(byte b, StringBuilder buf)
+ {
+ int d=0xf&((0xF0&b)>>4);
+ buf.append((char)((d>9?('A'-10):'0')+d));
+ d=0xf&b;
+ buf.append((char)((d>9?('A'-10):'0')+d));
+ }
+}
+
+
+
diff --git a/history.txt b/history.txt
index ac9306c56..68e84e941 100644
--- a/history.txt
+++ b/history.txt
@@ -1,3 +1,14 @@
+2014-08-19 zzz
+ * i2psnark:
+ - Don't filter create torrent form, and
+ fix exception on ':' in file names (ticket #1342)
+ - Don't remap file names on torrents we created, and
+ save remap setting in torrent config file (tickets #571, 771)
+ - Escaping fixes since names may not be remapped
+ - Use better encodePath() from Jetty
+ - Don't say create torrent succeeded when it didn't
+ - Add more sanity checks for base path of created torrent
+
2014-08-18 zzz
* i2psnark:
- Don't send HTML-only headers for icons
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index c10128fe6..fecba78d6 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 = 6;
+ public final static long BUILD = 7;
/** for example "-test" */
public final static String EXTRA = "";
|