Skip to content

Commit

Permalink
*) fixed Exceptions which caused 500 error when entering invalid URL …
Browse files Browse the repository at this point in the history
…mask or invalid prefer mask, invalid masks are ignored, error message is displayed on yacysearch.html (what about yacysearch.rss and yacysearch.json?)

*) fixed "more options" link on yacysearch.html

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7623 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
low012 committed Mar 23, 2011
1 parent 1a24917 commit 16cd919
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 19 deletions.
10 changes: 9 additions & 1 deletion htroot/yacysearch.html
Expand Up @@ -115,7 +115,7 @@ <h2>#[promoteSearchPageGreeting]#</h2>
#(searchvideo)#::<input type="radio" id="video" name="contentdom" value="video" #(check)#::checked="checked"#(/check)# /><label for="video">Video</label>&nbsp;&nbsp;#(/searchvideo)#
#(searchapp)#::<input type="radio" id="app" name="contentdom" value="app" #(check)#::checked="checked"#(/check)# /><label for="app">Applications</label>#(/searchapp)#
&nbsp;
<a href="index.html?searchoptions=1&amp;count=#[count]#&amp;urlmaskfilter=#[urlmaskfilter]#&amp;prefermaskfilter=#[prefermaskfilter]#&amp;cat=#[cat]#&amp;constraint=#[constraint]#&amp;contentdom=#[contentdom]#&amp;former=#[former]#&amp;meanCount=#[meanCount]#">more options</a>
<a href="index.html?searchoptions=2&amp;count=#[count]#&amp;urlmaskfilter=#[urlmaskfilter]#&amp;prefermaskfilter=#[prefermaskfilter]#&amp;cat=#[cat]#&amp;constraint=#[constraint]#&amp;contentdom=#[contentdom]#&amp;former=#[former]#&amp;meanCount=#[meanCount]#">more options</a>
</div>
#(/searchdomswitches)#
<input type="hidden" name="former" value="#[former]#" />
Expand All @@ -132,6 +132,14 @@ <h2>#[promoteSearchPageGreeting]#</h2>
<input type="hidden" name="meanCount" value="#[meanCount]#" />
</fieldset>
</form>
#(urlmaskerror)#::
<p><b>Illegal URL mask:</b> <i>#[urlmask]#</i> (not a valid regular expression), mask ignored.</p>
#(/urlmaskerror)#

#(prefermaskerror)#::
<p><b>Illegal prefer mask:</b> <i>#[prefermask]#</i> (not a valid regular expression), mask ignored.</b></p>
#(/prefermaskerror)#

#(didYouMean)#::
<p><b>Did you mean:</b> #{suggestions}# <a href="#[url]#">#[word]#</a> #[sep]##{/suggestions}#</p>
#(/didYouMean)#
Expand Down
26 changes: 24 additions & 2 deletions htroot/yacysearch.java
Expand Up @@ -33,6 +33,8 @@
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import net.yacy.cora.document.RSSMessage;
import net.yacy.cora.document.UTF8;
Expand Down Expand Up @@ -191,11 +193,11 @@ public static serverObjects respond(final RequestHeader header, final serverObje
}

String prefermask = (post == null) ? "" : post.get("prefermaskfilter", "");
if (prefermask.length() > 0 && prefermask.indexOf(".*") < 0) {
if (!prefermask.isEmpty() && prefermask.indexOf(".*") < 0) {
prefermask = ".*" + prefermask + ".*";
}

Bitfield constraint = (post != null && post.containsKey("constraint") && post.get("constraint", "").length() > 0) ? new Bitfield(4, post.get("constraint", "______")) : null;
Bitfield constraint = (post != null && post.containsKey("constraint") && !post.get("constraint", "").isEmpty()) ? new Bitfield(4, post.get("constraint", "______")) : null;
if (indexof) {
constraint = new Bitfield(4);
constraint.set(Condenser.flag_cat_indexof, true);
Expand Down Expand Up @@ -475,6 +477,26 @@ public static serverObjects respond(final RequestHeader header, final serverObje

// do the search
final HandleSet queryHashes = Word.words2hashesHandles(query[0]);

// check filters
try {
Pattern.compile(urlmask);
} catch (final PatternSyntaxException ex) {
Log.logWarning("SEARCH", "Illegal URL mask, not a valid regex: " + urlmask);
prop.put("urlmaskerror", 1);
prop.putHTML("urlmaskerror_urlmask", urlmask);
urlmask = ".*";
}

try {
Pattern.compile(prefermask);
} catch (final PatternSyntaxException ex) {
Log.logWarning("SEARCH", "Illegal prefer mask, not a valid regex: " + prefermask);
prop.put("prefermaskerror", 1);
prop.putHTML("prefermaskerror_prefermask", prefermask);
prefermask = "";
}

final QueryParams theQuery = new QueryParams(
originalquerystring,
queryHashes,
Expand Down
41 changes: 25 additions & 16 deletions source/de/anomic/search/QueryParams.java
Expand Up @@ -34,6 +34,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.document.UTF8;
Expand Down Expand Up @@ -191,9 +192,17 @@ public QueryParams(
this.contentdom = contentdom;
this.itemsPerPage = Math.min((specialRights) ? 1000 : 100, itemsPerPage);
this.offset = Math.min((specialRights) ? 10000 : 1000, offset);
this.urlMask = Pattern.compile(urlMask.toLowerCase());
try {
this.urlMask = Pattern.compile(urlMask.toLowerCase());
} catch (final PatternSyntaxException ex) {
throw new IllegalArgumentException("Not a valid regular expression: " + urlMask, ex);
}
this.urlMask_isCatchall = this.urlMask.toString().equals(catchall_pattern.toString());
this.prefer = Pattern.compile(prefer);
try {
this.prefer = Pattern.compile(prefer);
} catch (final PatternSyntaxException ex) {
throw new IllegalArgumentException("Not a valid regular expression: " + prefer, ex);
}
this.prefer_isMatchnothing = this.prefer.toString().equals(matchnothing_pattern.toString());
assert language != null;
this.targetlang = language;
Expand All @@ -204,7 +213,7 @@ public QueryParams(
this.constraint = constraint;
this.allofconstraint = allofconstraint;
this.sitehash = site; assert site == null || site.length() == 6;
this.authorhash = authorhash; assert authorhash == null || authorhash.length() > 0;
this.authorhash = authorhash; assert authorhash == null || !authorhash.isEmpty();
this.snippetCacheStrategy = snippetCacheStrategy;
this.host = host;
this.remotepeer = null;
Expand Down Expand Up @@ -326,7 +335,7 @@ public static TreeSet<String>[] cleanQuery(String querystring) {
final TreeSet<String> exclude = new TreeSet<String>(NaturalOrder.naturalComparator);
final TreeSet<String> fullquery = new TreeSet<String>(NaturalOrder.naturalComparator);

if ((querystring != null) && (querystring.length() > 0)) {
if ((querystring != null) && (!querystring.isEmpty())) {

// convert Umlaute
querystring = AbstractScraper.stripAll(querystring.toCharArray()).toLowerCase().trim();
Expand All @@ -341,20 +350,20 @@ public static TreeSet<String>[] cleanQuery(String querystring) {
int l;
// the string is clean now, but we must generate a set out of it
final String[] queries = querystring.split(" ");
for (int i = 0; i < queries.length; i++) {
if (queries[i].startsWith("-")) {
exclude.add(queries[i].substring(1));
for (String quer : queries) {
if (quer.startsWith("-")) {
exclude.add(quer.substring(1));
} else {
while ((c = queries[i].indexOf('-')) >= 0) {
s = queries[i].substring(0, c);
while ((c = quer.indexOf('-')) >= 0) {
s = quer.substring(0, c);
l = s.length();
if (l >= Condenser.wordminsize) {query.add(s);}
if (l > 0) {fullquery.add(s);}
queries[i] = queries[i].substring(c + 1);
quer = quer.substring(c + 1);
}
l = queries[i].length();
if (l >= Condenser.wordminsize) {query.add(queries[i]);}
if (l > 0) {fullquery.add(queries[i]);}
l = quer.length();
if (l >= Condenser.wordminsize) {query.add(quer);}
if (l > 0) {fullquery.add(quer);}
}
}
}
Expand All @@ -364,7 +373,7 @@ public static TreeSet<String>[] cleanQuery(String querystring) {
public String queryString(final boolean encodeHTML) {
final String ret;
if (encodeHTML){
ret =CharacterCoding.unicode2html(this.queryString, true);
ret = CharacterCoding.unicode2html(this.queryString, true);
} else {
ret = this.queryString;
}
Expand All @@ -375,7 +384,7 @@ public String queryStringForUrl() {
try {
return URLEncoder.encode(this.queryString, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
Log.logException(e);
return this.queryString;
}
}
Expand All @@ -388,7 +397,7 @@ public void filterOut(final SortedSet<String> blueList) {
// filter out words that appear in this set
// this is applied to the queryHashes
final HandleSet blues = Word.words2hashesHandles(blueList);
for (byte[] b: blues) queryHashes.remove(b);
for (final byte[] b: blues) queryHashes.remove(b);
}


Expand Down

0 comments on commit 16cd919

Please sign in to comment.