From 1bb0b135ac5dab0adab423d89612f7b1e13f2e61 Mon Sep 17 00:00:00 2001 From: luccioman Date: Tue, 27 Sep 2016 07:53:08 +0200 Subject: [PATCH] Avoid duplication of various MS Windows file URLs flavors Fix for mantis 692 (http://mantis.tokeek.de/view.php?id=692) --- source/net/yacy/cora/document/id/MultiProtocolURL.java | 7 ++++--- test/java/net/yacy/cora/document/id/DigestURLTest.java | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/net/yacy/cora/document/id/MultiProtocolURL.java b/source/net/yacy/cora/document/id/MultiProtocolURL.java index f4136350c..856a857c8 100644 --- a/source/net/yacy/cora/document/id/MultiProtocolURL.java +++ b/source/net/yacy/cora/document/id/MultiProtocolURL.java @@ -284,12 +284,13 @@ public class MultiProtocolURL implements Serializable, Comparable 4 && h.charAt(3) == ':' && h.charAt(4) != '/' && h.charAt(4) != '\\') { - // wrong windows path, after the doublepoint there should be a backslash - h = h.substring(0, 4) + '\\' + h.substring(4); + // wrong windows path, after the doublepoint there should be a backslash. Let's add a slash, as it will be slash in the normal form + h = h.substring(0, 4) + '/' + h.substring(4); } int q = h.indexOf('/', 2); if (q < 0 || h.length() > 3 && h.charAt(3) == ':') { - this.path = h.substring(2); // "path" or "c:/path" + // Missing root slash such as "path" or "c:/path" accepted, but the path attribute must by after all start with it + this.path = "/" + h.substring(2); } else { this.host = h.substring(2, q ); // TODO: handle "c:" ? if (this.host.equalsIgnoreCase(Domains.LOCALHOST)) this.host = null; diff --git a/test/java/net/yacy/cora/document/id/DigestURLTest.java b/test/java/net/yacy/cora/document/id/DigestURLTest.java index ffdca39c4..7756376f9 100644 --- a/test/java/net/yacy/cora/document/id/DigestURLTest.java +++ b/test/java/net/yacy/cora/document/id/DigestURLTest.java @@ -4,7 +4,6 @@ import java.net.MalformedURLException; import java.util.HashSet; import java.util.Set; import junit.framework.TestCase; -import static junit.framework.TestCase.assertEquals; import net.yacy.cora.document.encoding.ASCII; import org.junit.Test; @@ -43,11 +42,18 @@ public class DigestURLTest extends TestCase { String javaUrlStr = "file:///C:/tmp/test.html"; // allowed Java notation for Windows file system // allowed Windows notation - Set testUrls = new HashSet(); + Set testUrls = new HashSet(); + /* URLs mixing slashes and backslashes */ testUrls.add("file:///C:\\tmp\\test.html"); testUrls.add("file:///C:/tmp\\test.html"); testUrls.add("file:///C:\\tmp/test.html"); testUrls.add("file:///C:/tmp/test.html"); + + /* Wrong URLs missing slashes, however accepted by DigestURL and MultiProtocolURL constructors */ + testUrls.add("file://C:/tmp/test.html"); + testUrls.add("file://C:\\tmp\\test.html"); + testUrls.add("file://C:tmp/test.html"); + testUrls.add("file://C:tmp\\test.html"); DigestURL javaUrl = new DigestURL(javaUrlStr); String javaHashResult = ASCII.String(javaUrl.hash());