From b8daaacf6a1b04839c91120c2f75f5075b409c42 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Tue, 17 Feb 2026 22:58:02 +0100 Subject: Remove suspicious JavaScript code fragments from snippet lines. --- .../net/yacy/search/snippet/TextSnippetTest.java | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'test/java') 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
 

"; // test line with html, risk of snippet format issue + public void testDescriptionline() throws MalformedURLException { + String rawtestline = "Über großer test case
 

"; // 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. -- cgit v1.2.3