diff --git a/source/net/yacy/cora/document/id/MultiProtocolURL.java b/source/net/yacy/cora/document/id/MultiProtocolURL.java index e9c1e00bf..e4b84bca5 100644 --- a/source/net/yacy/cora/document/id/MultiProtocolURL.java +++ b/source/net/yacy/cora/document/id/MultiProtocolURL.java @@ -216,7 +216,7 @@ public class MultiProtocolURL implements Serializable, Comparable 0 && relPath.charAt(0) == '/') { this.path = relPath; @@ -647,7 +647,7 @@ public class MultiProtocolURL implements Serializable, Comparable q) { p = fileName.lastIndexOf('.', q); if (p < 0) return ""; } - return fileName.substring(p + 1, q).toLowerCase(); + return fileName.substring(p + 1, q).toLowerCase(Locale.ROOT); } /** @@ -933,7 +933,7 @@ public class MultiProtocolURL implements Serializable, Comparable 0 && "cgi.exe".indexOf(extension.toLowerCase()) >= 0; + return extension != null && extension.length() > 0 && "cgi.exe".indexOf(extension.toLowerCase(Locale.ROOT)) >= 0; } /** @@ -1232,14 +1232,14 @@ public class MultiProtocolURL implements Serializable, Comparable 0 && Response.docTypeExt(extension.toLowerCase()) == Response.DT_IMAGE; + return extension != null && extension.length() > 0 && Response.docTypeExt(extension.toLowerCase(Locale.ROOT)) == Response.DT_IMAGE; } public final boolean isIndividual() { - final String q = unescape(this.path.toLowerCase()); + final String q = unescape(this.path.toLowerCase(Locale.ROOT)); for (final String sid: sessionIDnames.keySet()) { - if (q.startsWith(sid.toLowerCase() + "=")) return true; - final int p = q.indexOf("&" + sid.toLowerCase() + "=",0); + if (q.startsWith(sid.toLowerCase(Locale.ROOT) + "=")) return true; + final int p = q.indexOf("&" + sid.toLowerCase(Locale.ROOT) + "=",0); if (p >= 0) return true; } int pos; @@ -1273,7 +1273,7 @@ public class MultiProtocolURL implements Serializable, Comparable 0) normalizedURL = normalizedURL.substring(p + 2); + // TODO lowering case in a locale sensitive manner makes sense here, but the used language locale should not dependant on the default system locale return splitpattern.split(normalizedURL.toLowerCase()); // word components of the url } diff --git a/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java b/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java index 482ccc2c7..2e18ac578 100644 --- a/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java +++ b/test/java/net/yacy/cora/document/id/MultiProtocolURLTest.java @@ -14,10 +14,12 @@ import java.util.Map; import java.util.TreeSet; import org.junit.Test; -//import junit.framework.TestCase; +/** + * Automated unit tests for the {@link MultiProtocolURL} class. + */ public class MultiProtocolURLTest { - + @Test public void testSessionIdRemoval() throws MalformedURLException { String[][] testURIs = new String[][]{ @@ -169,11 +171,19 @@ public class MultiProtocolURLTest { Map testurls = new HashMap(); // ( 1. parameter = urlstring to test, 2. parameter = expected protocol) testurls.put("http://host.com", "http"); + testurls.put("HTTP://EXAMPLE.COM", "http"); + testurls.put("https://host.com", "https"); testurls.put("HTTPS://host.com", "https"); + testurls.put("Ftp://example.org", "ftp"); + testurls.put("FTP://EXAMPLE.ORG", "ftp"); testurls.put("Ftp://host.com", "ftp"); + testurls.put("smb://host.com", "smb"); testurls.put("SMB://host.com", "smb"); testurls.put("/file.com", "file"); testurls.put("file://host.com/file.com", "file"); + testurls.put("file:///file1.txt", "file"); + testurls.put("FILE:///file2.txt", "file"); + testurls.put("MAILTO:Abc@host.com", "mailto"); testurls.put("MailTo:Abc@host.com", "mailto"); for (String txt : testurls.keySet()) { @@ -258,10 +268,12 @@ public class MultiProtocolURLTest { Map testurls = new HashMap(); // key=testurl, value=result testurls.put("path/file.xml","xml"); // easiest + testurls.put("/FILE.GIF","gif"); // easy upper case testurls.put("path/file?h.pdf",""); // file w/o extension testurls.put("file.html?param=h.pdf","html"); // dot in query part testurls.put("url?param=h.pdf",""); // dot in query part testurls.put("file.html?param", "html"); + testurls.put("FILE.GIF?param", "gif"); testurls.put("/path/",""); for (String s : testurls.keySet()) { System.out.println("test getFileExtension: " + s + " -> " + testurls.get(s));