From 16bc267a3238cec0cdbf1346c0598e9bf788edf0 Mon Sep 17 00:00:00 2001 From: reger Date: Sun, 1 Mar 2015 23:50:17 +0100 Subject: [PATCH] add test case for snippet html encoding check --- .../yacy/search/snippet/TextSnippetTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/net/yacy/search/snippet/TextSnippetTest.java b/test/net/yacy/search/snippet/TextSnippetTest.java index bd93f58c3..bd92903c6 100644 --- a/test/net/yacy/search/snippet/TextSnippetTest.java +++ b/test/net/yacy/search/snippet/TextSnippetTest.java @@ -1,6 +1,7 @@ package net.yacy.search.snippet; +import java.net.MalformedURLException; import net.yacy.cora.document.encoding.ASCII; import net.yacy.cora.document.id.DigestURL; import net.yacy.cora.federate.yacy.CacheStrategy; @@ -118,4 +119,38 @@ public class TextSnippetTest { } } + /** + * Test of descriptionline method, of class TextSnippet. + * 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 + + DigestURL url = new DigestURL("http://localhost/page.html"); + QueryGoal qg = new QueryGoal("test"); + + // test with raw line (no marking added by YaCy) + TextSnippet ts = new TextSnippet( + url.hash(), + rawtestline, + true, // isMarked, + TextSnippet.ResultClass.SOURCE_METADATA, ""); + + String sniptxt = ts.descriptionline(qg); // snippet text for display + System.out.println("testDescriptionline: snippet=" + sniptxt); + assertFalse ("HTML code not allowed in snippet text",sniptxt.contains("
")); // display text not to include unwanted html
+
+        // test with marking of query word
+         ts = new TextSnippet(
+            url.hash(),
+            rawtestline,
+            false, // isMarked,
+            TextSnippet.ResultClass.SOURCE_METADATA, "");
+
+        sniptxt = ts.descriptionline(qg);
+        System.out.println("testDescriptionline: snippet=" + sniptxt);
+        assertFalse ("HTML code not allowed in snippet text",sniptxt.contains("
")); // display text not to include unwanted html
+        assertTrue ("Query word not marked", sniptxt.contains("test")); // query word to be marked
+    }
 }