Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Avoid duplication of various MS Windows file URLs flavors
luccioman1bb0b135ac5d
diff --git a/source/net/yacy/cora/document/id/MultiProtocolURL.java b/source/net/yacy/cora/document/id/MultiProtocolURL.javaindex 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<MultiProtocolUthis.path = h.substring(2); // "/path" or "/c:/path"} else if (h.startsWith("//")) { // "//host/path" or "//host/c:/path"if (h.length() > 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.javaindex 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<String> testUrls = new HashSet();+ Set<String> testUrls = new HashSet<String>();+ /* 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());