Avoid duplication of various MS Windows file URLs flavors

Fix for mantis 692 (http://mantis.tokeek.de/view.php?id=692)
pull/77/head
luccioman 9 years ago
parent b9a8476f02
commit 1bb0b135ac

@ -284,12 +284,13 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
this.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;

@ -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());

Loading…
Cancel
Save