Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

* fix StringIndexOutOfBoundException in WebStructureGraph * add better escaping to saveMap and loadMap

f1ori982aa689ef48
diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java
index a60d62b31..f0aaeabe8 100644
--- a/source/de/anomic/search/Switchboard.java
+++ b/source/de/anomic/search/Switchboard.java
@@ -480,7 +480,7 @@ public final class Switchboard extends serverSwitch {
// define a realtime parsable mimetype list
log.logConfig("Parser: Initializing Mime Type deny list");
- TextParser.setDenyMime(getConfig(SwitchboardConstants.PARSER_MIME_DENY, null));
+ TextParser.setDenyMime(getConfig(SwitchboardConstants.PARSER_MIME_DENY, ""));
// start a loader
log.logConfig("Starting Crawl Loader");
diff --git a/source/de/anomic/yacy/graphics/WebStructureGraph.java b/source/de/anomic/yacy/graphics/WebStructureGraph.java
index f679136f4..bd327a524 100644
--- a/source/de/anomic/yacy/graphics/WebStructureGraph.java
+++ b/source/de/anomic/yacy/graphics/WebStructureGraph.java
@@ -77,7 +77,7 @@ public class WebStructureGraph {
for (final Map.Entry<String, String> entry : this.structure_old.entrySet()) {
key = entry.getKey();
value = entry.getValue();
- delset.add(value.substring(0, 8) + key);
+ if (value.length() >= 8) delset.add(value.substring(0, 8) + key);
}
int delcount = this.structure_old.size() - (maxhosts * 9 / 10);
final Iterator<String> j = delset.iterator();
diff --git a/source/net/yacy/kelondro/util/FileUtils.java b/source/net/yacy/kelondro/util/FileUtils.java
index 5dc22f722..f868cdde5 100644
--- a/source/net/yacy/kelondro/util/FileUtils.java
+++ b/source/net/yacy/kelondro/util/FileUtils.java
@@ -412,10 +412,12 @@ public final class FileUtils {
String key, value;
for (final Map.Entry<String, String> entry: props.entrySet()) {
key = entry.getKey();
+ if (key != null)
+ key = key.replace("\\", "\\\\").replace("\n", "\\n").replace("=", "\\=");
if (entry.getValue() == null) {
value = "";
} else {
- value = entry.getValue().replaceAll("\n", "\\\\n");
+ value = entry.getValue().replace("\\", "\\\\").replace("\n", "\\n");
}
pw.println(key + "=" + value);
}
@@ -505,13 +507,21 @@ public final class FileUtils {
}
public static Map<String, String> table(Iterator<String> li) {
- int pos;
String line;
final HashMap<String, String> props = new HashMap<String, String>();
while (li.hasNext()) {
- line = li.next();
- pos = line.indexOf('=');
- if (pos > 0) props.put(line.substring(0, pos).trim(), line.substring(pos + 1).trim());
+ int pos = 0;
+ line = li.next().trim();
+ if (line.length() > 0 && line.charAt(0) == '#') continue; // exclude comments
+ do {
+ // search for unescaped =
+ pos = line.indexOf('=', pos+1);
+ } while ( pos > 0 && line.charAt(pos-1) == '\\');
+ if (pos > 0) {
+ String key = line.substring(0, pos).trim().replace("\\=", "=").replace("\\n", "\n").replace("\\", "\\");
+ String value = line.substring(pos + 1).trim().replace("\\n", "\n").replace("\\\\", "\\");
+ props.put(key, value);
+ }
}
return props;
}
@@ -519,34 +529,6 @@ public final class FileUtils {
public static Map<String, String> table(final byte[] a) {
return table(strings(a));
}
-
- /**
- * parse config files
- *
- * splits the lines in list into pairs sperarated by =, lines beginning with # are ignored
- * ie:
- * abc=123
- * # comment
- * fg=dcf
- * => Map{abc => 123, fg => dcf}
- * @param list
- * @return
- */
- public static Map<String, String> table(final ArrayList<String> list) {
- if (list == null) return new HashMap<String, String>();
- final Iterator<String> i = list.iterator();
- int pos;
- String line;
- final HashMap<String, String> props = new HashMap<String, String>(list.size());
- while (i.hasNext()) {
- line = i.next().trim();
- if (line.length() > 0 && line.charAt(0) == '#') continue; // exclude comments
- //System.out.println("NXTOOLS_PROPS - LINE:" + line);
- pos = line.indexOf('=');
- if (pos > 0) props.put(line.substring(0, pos).trim(), line.substring(pos + 1).trim());
- }
- return props;
- }
public static Iterator<String> strings(byte[] a) {
if (a == null) return new ArrayList<String>().iterator();