Skip to content
Snippets Groups Projects
Commit 924f6783 authored by srosse's avatar srosse
Browse files

OO-754: escape the highlighted text (prevent html code or xml code to break our layout)

parent 281ae111
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ import org.apache.lucene.search.TopDocs; ...@@ -41,6 +41,7 @@ import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.highlight.Highlighter; import org.apache.lucene.search.highlight.Highlighter;
import org.apache.lucene.search.highlight.InvalidTokenOffsetsException; import org.apache.lucene.search.highlight.InvalidTokenOffsetsException;
import org.apache.lucene.search.highlight.QueryScorer; import org.apache.lucene.search.highlight.QueryScorer;
import org.apache.lucene.search.highlight.SimpleHTMLEncoder;
import org.apache.lucene.search.highlight.SimpleHTMLFormatter; import org.apache.lucene.search.highlight.SimpleHTMLFormatter;
import org.olat.core.commons.persistence.DBFactory; import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.commons.services.search.AbstractOlatDocument; import org.olat.core.commons.services.search.AbstractOlatDocument;
...@@ -244,7 +245,8 @@ public class SearchResultsImpl implements SearchResults { ...@@ -244,7 +245,8 @@ public class SearchResultsImpl implements SearchResults {
* @throws IOException * @throws IOException
*/ */
private void doHighlight(Query query, Analyzer analyzer, Document doc, ResultDocument resultDocument) throws IOException { private void doHighlight(Query query, Analyzer analyzer, Document doc, ResultDocument resultDocument) throws IOException {
Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter(HIGHLIGHT_PRE_TAG,HIGHLIGHT_POST_TAG) , new QueryScorer(query)); Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter(HIGHLIGHT_PRE_TAG,HIGHLIGHT_POST_TAG) ,
new SimpleHTMLEncoder(), new QueryScorer(query));
// Get 3 best fragments of content and seperate with a "..." // Get 3 best fragments of content and seperate with a "..."
try { try {
//highlight content //highlight content
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment