From b4438e8606c8e44dfc747c531a60ab1bf6a93737 Mon Sep 17 00:00:00 2001 From: Christian Aistleitner Date: Thu, 30 May 2013 22:20:41 +0200 Subject: [PATCH] Fix highlighting of matches in text of escaped html entities When highlighting matches in suggestions, the highlighting also matched text of escaped html entities. So for example typing "owner:L" in the search box showed a mangled "<" in front of the email address: "Lucy <mail@example.org>" (with all "L", and "l" in bold) instead of the plain "Lucy " (with all "L", and "l" in bold) We now un-mangle such matches in text of escaped html entities. Bug: issue 1574 Change-Id: Ifc0b4f4d52a2b2a5a6a511b943a11d752c186c39 --- .../safehtml/client/HighlightSuggestOracle.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/HighlightSuggestOracle.java b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/HighlightSuggestOracle.java index e2c576bce3..61bec18fa3 100644 --- a/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/HighlightSuggestOracle.java +++ b/gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/HighlightSuggestOracle.java @@ -79,7 +79,18 @@ public abstract class HighlightSuggestOracle extends SuggestOracle { if (!html) { ds = escape(ds); } - displayString = sgi(ds, qstr, "$1"); + + // We now surround qstr by . But the chosen approach is not too + // smooth, if qstr is small (e.g.: "t") and this small qstr may occur in + // escapes (e.g.: "Tim <email@example.org>"). Those escapes will + // get -ed as well (e.g.: "<" -> "&lt;"). But + // as repairing those mangled escapes is easier than not mangling them in + // the first place, we repair them afterwards. + ds = sgi(ds, qstr, "$1"); + // Repairing -ed escapes. + ds = sgi(ds, "(&[a-z]*)([a-z]*)([a-z]*;)", "$1$2$3"); + + displayString = ds; } private static native String sgi(String inString, String pat, String newHtml)