diff --git a/source/net/yacy/repository/Blacklist.java b/source/net/yacy/repository/Blacklist.java index 8688d5e1e..ce72e689e 100644 --- a/source/net/yacy/repository/Blacklist.java +++ b/source/net/yacy/repository/Blacklist.java @@ -466,6 +466,14 @@ public class Blacklist { return s != null && s.has(urlHash); } + /** + * Check blacklist to contain given host & path pattern. + * To check if a url matches a blacklist pattern, use isListed() + * @param blacklistType + * @param host + * @param path + * @return + */ public final boolean contains(final BlacklistType blacklistType, final String host, final String path) { boolean ret = false; @@ -477,7 +485,13 @@ public class Blacklist { final Set hostList = blacklistMap.get(h); if (hostList != null) { - ret = hostList.contains(path); + for (Pattern hp : hostList) { + String hpxs = hp.pattern(); + if (hpxs.equals(path)) { + ret = true; + break; + } + } } } return ret; diff --git a/test/java/net/yacy/repository/BlacklistTest.java b/test/java/net/yacy/repository/BlacklistTest.java new file mode 100644 index 000000000..3c48fbd58 --- /dev/null +++ b/test/java/net/yacy/repository/BlacklistTest.java @@ -0,0 +1,43 @@ +package net.yacy.repository; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Pattern; +import net.yacy.cora.document.id.Punycode; +import org.junit.Test; +import static org.junit.Assert.*; + +public class BlacklistTest { + + /** + * Simulates contains method, of class Blacklist as proof for pattern.toString + * needed and works + */ + @Test + public void testContains() throws Punycode.PunycodeException { + String path = ".*"; // simplest test pattern + + Pattern pattern = Pattern.compile(path, Pattern.CASE_INSENSITIVE); + + // pattern list as in Blacklist class + // ConcurrentMap>> hostpaths_matchable; + // simulate last part, path pattern set + Set hostList = new HashSet(); + hostList.add(pattern); + + // proof assumption pattern(path) != path + boolean ret = hostList.contains(path); + assertFalse("match blacklist pattern " + path, ret); + + // proof pattern.toString match works + for (Pattern hp : hostList) { + String hpxs = hp.pattern(); + if (hpxs.equals(path)) { + ret = true; + break; + } + } + assertTrue("match blacklist pattern " + path, ret); + } + +}