mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
fix Blacklist.contains() matching path pattern to string
similar to 5e9e871192
+ add proof testcase
This commit is contained in:
parent
5e9e871192
commit
5e335b32da
|
@ -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<Pattern> 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;
|
||||
|
|
43
test/java/net/yacy/repository/BlacklistTest.java
Normal file
43
test/java/net/yacy/repository/BlacklistTest.java
Normal file
|
@ -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<BlacklistType, Map<String, Set<Pattern>>> hostpaths_matchable;
|
||||
// simulate last part, path pattern set
|
||||
Set<Pattern> hostList = new HashSet<Pattern>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user