Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) Bugfix for resolveBackpath problem with tailing /.. *) Junit testclass for resolveBackpath testing
thelicfe54fedc7ce
diff --git a/source/de/anomic/net/URL.java b/source/de/anomic/net/URL.javaindex d20ca0ccf..019eae042 100644--- a/source/de/anomic/net/URL.java+++ b/source/de/anomic/net/URL.java@@ -161,7 +161,7 @@ public class URL {}// resolve '..'- private String resolveBackpath(String path) /* throws MalformedURLException */ {+ String resolveBackpath(String path) /* throws MalformedURLException */ {/* original version by [MC]int p;while ((p = path.indexOf("/..")) >= 0) {@@ -174,7 +174,7 @@ public class URL {/* by [MT] */if (path.length() == 0 || path.charAt(0) != '/') { path = "/" + path; }- Pattern pathPattern = Pattern.compile("(/[^/\\.]+/)[.]{2}(?=/)|/\\.(?=/)|/(?=/)");+ Pattern pathPattern = Pattern.compile("(/[^/]+(?<!/\\.{1,2})/)[.]{2}(?=/|$)|/\\.(?=/)|/(?=/)");Matcher matcher = pathPattern.matcher(path);while (matcher.find()) {path = matcher.replaceAll("");@@ -183,7 +183,7 @@ public class URL {/* another version at http://www.yacy-forum.de/viewtopic.php?p=26871#26871 */- return path;+ return path.equals("")?"/":path;}/**diff --git a/test/de/anomic/net/URLTest.java b/test/de/anomic/net/URLTest.javanew file mode 100644index 000000000..518d201b5--- /dev/null+++ b/test/de/anomic/net/URLTest.java@@ -0,0 +1,40 @@+package de.anomic.net;++import java.net.MalformedURLException;++import junit.framework.TestCase;++public class URLTest extends TestCase {++ public void testResolveBackpath() throws MalformedURLException {+ String[][] testStrings = new String[][] {+ new String[]{"/..home","/..home"},+ new String[]{"/test/..home/test.html","/test/..home/test.html"},+ new String[]{"/../","/../"},+ new String[]{"/..","/.."},+ new String[]{"/test/..","/"},+ new String[]{"/test/../","/"},+ new String[]{"/test/test2/..","/test"},+ new String[]{"/test/test2/../","/test/"},+ new String[]{"/test/test2/../hallo","/test/hallo"},+ new String[]{"/test/test2/../hallo/","/test/hallo/"},+ new String[]{"/home/..test/../hallo/../","/home/"}+ };++ URL urlObj = new URL("http://yacy.net");+ for (int i=0; i < testStrings.length; i++) {+ // desired conversion result+ System.out.print("testResolveBackpath: " + testStrings[i][0]);+ String shouldBe = testStrings[i][1];++ // conversion result+ String resolvedURL = urlObj.resolveBackpath(testStrings[i][0]);++ // test if equal+ assertEquals(shouldBe,resolvedURL);+ System.out.println(" -> " + resolvedURL);++ }+ }++}