Pattern.quote() replaces \\Q and \\E according to publication in

http://www.cs.washington.edu/homes/mernst/pubs/regex-types-ftfjp2012.pdf
pull/1/head
Michael Peter Christen 13 years ago
parent db9d81cb7a
commit 5b3acc12cd

@ -1,5 +1,5 @@
/**
* oad_RSS_p
* Load_RSS_p
* Copyright 2010 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
* First released 20.08.2010 at http://yacy.net
*
@ -26,6 +26,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import net.yacy.cora.document.Hit;
import net.yacy.cora.document.RSSFeed;
@ -83,7 +84,7 @@ public class Load_RSS_p {
if (messageurl.length() == 0) continue;
final byte[] api_pk = row.get("api_pk");
final Row r = api_pk == null ? null : sb.tables.select("api", api_pk);
if (r == null || !r.get("comment", "").matches(".*\\Q" + messageurl + "\\E.*")) {
if (r == null || !r.get("comment", "").matches(".*" + Pattern.quote(messageurl) + ".*")) {
d.add(row.getPK());
}
}
@ -125,7 +126,7 @@ public class Load_RSS_p {
if (messageurl.length() == 0) continue;
final byte[] api_pk = row.get("api_pk");
final Row r = api_pk == null ? null : sb.tables.select("api", api_pk);
if (r != null && r.get("comment", "").matches(".*\\Q" + messageurl + "\\E.*")) {
if (r != null && r.get("comment", "").matches(".*" + Pattern.quote(messageurl) + ".*")) {
d.add(row.getPK());
}
}
@ -194,7 +195,7 @@ public class Load_RSS_p {
// check if feed is registered in scheduler
final byte[] api_pk = row.get("api_pk");
final Row r = api_pk == null ? null : sb.tables.select("api", api_pk);
if (r != null && r.get("comment", "").matches(".*\\Q" + messageurl + "\\E.*")) {
if (r != null && r.get("comment", "").matches(".*" + Pattern.quote(messageurl) + ".*")) {
// this is a recorded entry
final Date date_next_exec = r.get(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, (Date) null);
prop.put("showscheduledfeeds_list_" + apic + "_pk", UTF8.String(row.getPK()));

@ -119,10 +119,9 @@ public class YMarkCrawlStart extends HashMap<String,String>{
private void load() {
try {
final StringBuilder buffer = new StringBuilder(500);
//buffer.append("^.*crawlingURL=\\Q");
buffer.append("^crawl start for \\Q");
buffer.append(url);
buffer.append("\\E?.*");
buffer.append("^crawl start for ");
buffer.append(Pattern.quote(url));
buffer.append("?.*");
final Pattern pattern = Pattern.compile(buffer.toString());
//final Iterator<Tables.Row> APIcalls = this.worktables.iterator(WorkTables.TABLE_API_NAME, WorkTables.TABLE_API_COL_URL, pattern);
final Iterator<Tables.Row> APIcalls = this.worktables.iterator(WorkTables.TABLE_API_NAME, WorkTables.TABLE_API_COL_COMMENT, pattern);

@ -92,8 +92,6 @@ public class YMarkTables {
public final static String ADMIN_AUTHENTICATE_MSG = "Admin authentication required!";
public final static String p1 = "(?:^|.*,)";
public final static String p2 = "\\Q";
public final static String p3 = "\\E";
public final static String p4 = "(?:,.*|$)";
public final static String p5 = "((?:";
public final static String p6 = ")(?:,.*|$)){";
@ -194,9 +192,7 @@ public class YMarkTables {
patternBuilder.setLength(0);
patternBuilder.append(p1);
patternBuilder.append('(');
patternBuilder.append(p2);
patternBuilder.append(folder);
patternBuilder.append(p3);
patternBuilder.append(Pattern.quote(folder));
patternBuilder.append(')');
patternBuilder.append(p4);
final Pattern p = Pattern.compile(patternBuilder.toString());
@ -210,9 +206,7 @@ public class YMarkTables {
patternBuilder.append(p1);
patternBuilder.append(p5);
for (final String tag : tagArray) {
patternBuilder.append(p2);
patternBuilder.append(tag);
patternBuilder.append(p3);
patternBuilder.append(Pattern.quote(tag));
patternBuilder.append('|');
}
patternBuilder.deleteCharAt(patternBuilder.length()-1);

Loading…
Cancel
Save