You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/09/26 08:12:22 UTC
(maven-indexer) branch master updated: Escape HTML in highlighted match fragments
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-indexer.git
The following commit(s) were added to refs/heads/master by this push:
new 60795898 Escape HTML in highlighted match fragments
60795898 is described below
commit 607958989aaa2a0df8bcf83770c72e0941fb641f
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Sat Sep 26 02:19:45 2026 +0200
Escape HTML in highlighted match fragments
MatchHighlightMode.HTML fragments wrap matches in <B> but copied the
surrounding text as is. The text is now HTML-escaped; callers that
escaped the fragments themselves must stop doing so.
---
.../org/apache/maven/index/CleaningEncoder.java | 6 ++++-
.../apache/maven/index/CleaningEncoderTest.java} | 26 ++++++++++++++++++----
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/indexer-core/src/main/java/org/apache/maven/index/CleaningEncoder.java b/indexer-core/src/main/java/org/apache/maven/index/CleaningEncoder.java
index 4b4c1335..e8f29b86 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/CleaningEncoder.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/CleaningEncoder.java
@@ -19,9 +19,13 @@
package org.apache.maven.index;
import org.apache.lucene.search.highlight.Encoder;
+import org.apache.lucene.search.highlight.SimpleHTMLEncoder;
+/**
+ * Encodes text of {@link MatchHighlightMode#HTML} fragments: escapes it as HTML and removes line breaks.
+ */
public class CleaningEncoder implements Encoder {
public String encodeText(String originalText) {
- return originalText.replace("\n", "");
+ return SimpleHTMLEncoder.htmlEncode(originalText).replace("\n", "");
}
}
diff --git a/indexer-core/src/main/java/org/apache/maven/index/CleaningEncoder.java b/indexer-core/src/test/java/org/apache/maven/index/CleaningEncoderTest.java
similarity index 56%
copy from indexer-core/src/main/java/org/apache/maven/index/CleaningEncoder.java
copy to indexer-core/src/test/java/org/apache/maven/index/CleaningEncoderTest.java
index 4b4c1335..d55cfec0 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/CleaningEncoder.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/CleaningEncoderTest.java
@@ -18,10 +18,28 @@
*/
package org.apache.maven.index;
-import org.apache.lucene.search.highlight.Encoder;
+import org.junit.jupiter.api.Test;
-public class CleaningEncoder implements Encoder {
- public String encodeText(String originalText) {
- return originalText.replace("\n", "");
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * UT for {@link CleaningEncoder}.
+ */
+public class CleaningEncoderTest {
+ private final CleaningEncoder encoder = new CleaningEncoder();
+
+ @Test
+ public void plainTextIsUnchanged() {
+ assertEquals("commons logging", encoder.encodeText("commons logging"));
+ }
+
+ @Test
+ public void textIsHtmlEscaped() {
+ assertEquals("a <b> & "c"", encoder.encodeText("a <b> & \"c\""));
+ }
+
+ @Test
+ public void lineBreaksAreRemoved() {
+ assertEquals("line oneline two", encoder.encodeText("line one\nline two"));
}
}