Skip to content

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

fix formatting issue if snippet contains html code replacement for reverted commit https://gitorious.org/yacy/rc1/commit/61f42a792872c7fc83c7d4d64e1f0bb9d063c810

regerfba34e12eff6
diff --git a/source/net/yacy/search/snippet/TextSnippet.java b/source/net/yacy/search/snippet/TextSnippet.java
index 9b516922b..163141a3e 100644
--- a/source/net/yacy/search/snippet/TextSnippet.java
+++ b/source/net/yacy/search/snippet/TextSnippet.java
@@ -343,6 +343,17 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
init(url.hash(), textline, false, source, null);
}
+ /**
+ * Init a snippet line for urlhash, used for display in search results.
+ * HTML code in text will be html-encoded.
+ * If the input is already marked (highlightened) <b>...</b> tags are kept as is.
+ *
+ * @param urlhash hash of the url for this snippet
+ * @param line text to use as snippet
+ * @param isMarked true if query words already marked in input text
+ * @param errorCode
+ * @param errortext
+ */
private void init(
final byte[] urlhash,
final String line,
@@ -350,7 +361,15 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
final ResultClass errorCode,
final String errortext) {
this.urlhash = urlhash;
- this.line = line;
+ if (line != null) { // line may contain html code (possible to mess up result display)
+ if (isMarked) { // if marked, keep <b>...</b> html tags in place
+ this.line = CharacterCoding.unicode2html(line, false).replaceAll("&lt;b&gt;(.+?)&lt;/b&gt;", "<b>$1</b>");
+ } else { // otherwise encode all text for html display
+ this.line = CharacterCoding.unicode2html(line, false);
+ }
+ } else {
+ this.line = line;
+ }
this.isMarked = isMarked;
this.resultStatus = errorCode;
this.error = errortext;