From b96386e3da4c5e2f193c27d631e2d7cf3ba28887 Mon Sep 17 00:00:00 2001 From: low012 Date: Mon, 25 Jun 2007 19:39:15 +0000 Subject: [PATCH] *) No stacktrace anymore if invalid regex is entered in search box, insted an error message gets displayed. This has no effect on Network.xml which will present all peernames if an invalid regex is entered now. I'm not sure if this is a desired behavior or if it was better to not return any results at all. Any suggestions? git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3923 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Network.html | 4 ++++ htroot/Network.java | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/htroot/Network.html b/htroot/Network.html index 1c82147d7..aedc41c1a 100644 --- a/htroot/Network.html +++ b/htroot/Network.html @@ -31,6 +31,10 @@ ::

Manually contacting Peer

#(/page)# + #(regexerror)# + :: +

ERROR: Unable to execute query. "#[wrongregex]#" is no valid regular expression, please enter a valid regular expression to search for a peername.

+ #(/regexerror)# #(table)#

no remote #[peertype]# peer for this list known

:: diff --git a/htroot/Network.java b/htroot/Network.java index 827fa1c68..e6a274e76 100644 --- a/htroot/Network.java +++ b/htroot/Network.java @@ -53,6 +53,7 @@ import java.util.HashSet; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import de.anomic.http.httpHeader; import de.anomic.http.httpc; @@ -307,13 +308,23 @@ public class Network { double QPM; long myValue=0, nextValue=0, prevValue=0, nextPPM=0, myPPM=0; Pattern peerSearchPattern = null; + String wrongregex = null; + prop.put("regexerror", 0); + prop.put("wrongregex", (String)null); if(post.containsKey("search")) { - peerSearchPattern = Pattern.compile(post.get("match", ""), Pattern.CASE_INSENSITIVE); + try{ + peerSearchPattern = Pattern.compile(post.get("match", ""), Pattern.CASE_INSENSITIVE); + } + catch (PatternSyntaxException pse){ + wrongregex = pse.getPattern(); + prop.put("regexerror", 1); + prop.put("regexerror_wrongregex", wrongregex); + } } while (e.hasMoreElements() && conCount < maxCount) { seed = (yacySeed) e.nextElement(); if (seed != null) { - if(post.containsKey("search")) { + if((post.containsKey("search")) && (wrongregex == null)) { boolean abort = true; Matcher m = peerSearchPattern.matcher (seed.getName()); if (m.find ()) {