From 982aa689ef485f808c1635a0c002718fd6be4918 Mon Sep 17 00:00:00 2001 From: f1ori Date: Mon, 31 Jan 2011 14:25:09 +0000 Subject: [PATCH] * fix StringIndexOutOfBoundException in WebStructureGraph * add better escaping to saveMap and loadMap git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7458 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/search/Switchboard.java | 2 +- .../yacy/graphics/WebStructureGraph.java | 2 +- source/net/yacy/kelondro/util/FileUtils.java | 48 ++++++------------- 3 files changed, 17 insertions(+), 35 deletions(-) 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 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 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 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 table(Iterator li) { - int pos; String line; final HashMap props = new HashMap(); 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 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 table(final ArrayList list) { - if (list == null) return new HashMap(); - final Iterator i = list.iterator(); - int pos; - String line; - final HashMap props = new HashMap(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 strings(byte[] a) { if (a == null) return new ArrayList().iterator();