From cb3366c3e95d57dcc6f766191cbd5b4fa251f10d Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Tue, 17 Feb 2026 22:47:32 +0100 Subject: fixed parsing of x-data-elements in
--- .../net/yacy/document/parser/htmlParserTest.java | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'test/java') diff --git a/test/java/net/yacy/document/parser/htmlParserTest.java b/test/java/net/yacy/document/parser/htmlParserTest.java index 760326ee1..5b87fdf88 100644 --- a/test/java/net/yacy/document/parser/htmlParserTest.java +++ b/test/java/net/yacy/document/parser/htmlParserTest.java @@ -470,4 +470,82 @@ public class htmlParserTest { System.out.println("ScraperScriptTagTest: [" + textSource + "] = [" + txt + "]"); assertEquals(txt, textSource); } + + /** + * Test for parseToScraper of class htmlParser with quoted attribute content + * containing ">" characters (for example Alpine.js x-data arrow functions). + * Attribute values must never leak as plain text. + */ + @Test + public void testParseToScraper_QuotedAttributeWithGt() throws MalformedURLException, IOException { + final AnchorURL url = new AnchorURL("http://localhost/"); + final String charset = StandardCharsets.UTF_8.name(); + final String textSource = "Visible text"; + final String testhtml = "" + + "
{" + + "this.mobileMainNavHeight = el.getBoundingClientRect().height;" + + "});" + + "}" + + "}\">" + + "

" + textSource + "

" + + "
" + + ""; + + final ContentScraper scraper = parseToScraper(url, charset, TagValency.IGNORE, new HashSet(), + new VocabularyScraper(), 0, testhtml, 10, 10); + + final String txt = scraper.getText(); + assertEquals(textSource + ".", txt); + assertFalse(txt.contains("getBoundingClientRect")); + assertFalse(txt.contains("mobileMainNavHeight")); + } + + /** + * Test for parseToScraper of class htmlParser with quoted attribute content + * containing a comparison using ">" and additional Alpine-style attributes. + * Attribute names/values must never leak as plain text. + */ + @Test + public void testParseToScraper_QuotedAttributeComparisonGt() throws MalformedURLException, IOException { + final AnchorURL url = new AnchorURL("http://localhost/"); + final String charset = StandardCharsets.UTF_8.name(); + final String textSource = "Next image"; + final String testhtml = "" + + "" + + ""; + + final ContentScraper scraper = parseToScraper(url, charset, TagValency.IGNORE, new HashSet(), + new VocabularyScraper(), 0, testhtml, 10, 10); + + final String txt = scraper.getText(); + assertTrue(txt.contains(textSource)); + assertFalse(txt.contains("@click")); + assertFalse(txt.contains("lightboxPrev")); + assertFalse(txt.contains("imgModalItems.length")); + } } -- cgit v1.2.3