From 38b103f8ccc860b92e7f85f795aecf0c2296f68e Mon Sep 17 00:00:00 2001 From: millmanorama Date: Thu, 23 Feb 2017 12:50:19 +0100 Subject: [PATCH] escape the keyword in the same way we escape the text so that they will actually match --- .../autopsy/keywordsearch/HighlightedText.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/HighlightedText.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/HighlightedText.java index d2d7e1ea9c..ef7897502b 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/HighlightedText.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/HighlightedText.java @@ -468,10 +468,13 @@ class HighlightedText implements IndexedText { StringBuilder highlightedText = new StringBuilder(""); + //do a highlighting pass for each keyword for (String keyword : keywords) { + //we also need to escape the keyword so that it matches the escpared text + final String escapedKeyword = StringEscapeUtils.escapeHtml(keyword); int textOffset = 0; int hitOffset; - while ((hitOffset = StringUtils.indexOfIgnoreCase(text, keyword, textOffset)) != -1) { + while ((hitOffset = StringUtils.indexOfIgnoreCase(text, escapedKeyword, textOffset)) != -1) { // Append the portion of text up to (but not including) the hit. highlightedText.append(text.substring(textOffset, hitOffset)); // Add in the highlighting around the keyword. @@ -480,15 +483,15 @@ class HighlightedText implements IndexedText { highlightedText.append(HIGHLIGHT_POST); // Advance the text offset past the keyword. - textOffset = hitOffset + keyword.length(); + textOffset = hitOffset + escapedKeyword.length(); } // Append the remainder of text field highlightedText.append(text.substring(textOffset, text.length())); - if (highlightedText.length() > 0) { - - } else { + + if (highlightedText.length() == 0) { return NbBundle.getMessage(HighlightedText.class, "HighlightedMatchesSource.getMarkup.noMatchMsg"); - } + } + //reset for next pass text = highlightedText.toString(); highlightedText = new StringBuilder(""); }