summaryrefslogtreecommitdiff
path: root/test/java
diff options
context:
space:
mode:
authorMichael Peter Christen <mc@yacy.net>2026-02-17 22:58:02 +0100
committerMichael Peter Christen <mc@yacy.net>2026-02-17 22:58:02 +0100
commitb8daaacf6a1b04839c91120c2f75f5075b409c42 (patch)
tree287e9bc8f13d09aa662eec5898054ab01d7115d6 /test/java
parentcb3366c3e95d57dcc6f766191cbd5b4fa251f10d (diff)
Remove suspicious JavaScript code fragments from snippet lines.
Diffstat (limited to 'test/java')
-rw-r--r--test/java/net/yacy/search/snippet/TextSnippetTest.java28
1 files changed, 23 insertions, 5 deletions
diff --git a/test/java/net/yacy/search/snippet/TextSnippetTest.java b/test/java/net/yacy/search/snippet/TextSnippetTest.java
index 2d12c5d24..c89cee47e 100644
--- a/test/java/net/yacy/search/snippet/TextSnippetTest.java
+++ b/test/java/net/yacy/search/snippet/TextSnippetTest.java
@@ -158,8 +158,8 @@ public class TextSnippetTest {
* checking poper encoding of remaining html in raw snippet line.
*/
@Test
- public void testDescriptionline() throws MalformedURLException {
- String rawtestline = "Über großer test case </span> <pre> <hr><hr /></pre>"; // test line with html, risk of snippet format issue
+ public void testDescriptionline() throws MalformedURLException {
+ String rawtestline = "Über großer test case </span> <pre> <hr><hr /></pre>"; // test line with html, risk of snippet format issue
DigestURL url = new DigestURL("http://localhost/page.html");
QueryGoal qg = new QueryGoal("test");
@@ -196,9 +196,27 @@ public class TextSnippetTest {
TextSnippet.ResultClass.SOURCE_METADATA, "");
sniptxt = ts.descriptionline(qg);
System.out.println("testDescriptionline: (with numbers) snippet="+sniptxt);
- assertTrue ("number (.) broken up",sniptxt.contains("1.83"));
- assertTrue ("number (,) broken up",sniptxt.contains("3,14"));
- }
+ assertTrue ("number (.) broken up",sniptxt.contains("1.83"));
+ assertTrue ("number (,) broken up",sniptxt.contains("3,14"));
+ }
+
+ @Test
+ public void testDescriptionlineRemovesSuspiciousJavaScriptBraceBlock() throws MalformedURLException {
+ final String rawtestline = "Springe zur Suche Springe zum Fußbereich { this.mobileMainNavHeight = el.getBoundingClientRect().height; }); } }";
+ final DigestURL url = new DigestURL("http://localhost/page.html");
+ final QueryGoal qg = new QueryGoal("Suche");
+
+ final TextSnippet ts = new TextSnippet(
+ url,
+ rawtestline,
+ true,
+ TextSnippet.ResultClass.SOURCE_METADATA, "");
+
+ final String sniptxt = ts.descriptionline(qg);
+ assertTrue(sniptxt.contains("Springe zur Suche"));
+ assertFalse(sniptxt.contains("getBoundingClientRect"));
+ assertFalse(sniptxt.contains("mobileMainNavHeight"));
+ }
/**
* Run text snippet extraction from a given plain text file.