diff options
| author | reger <reger18@arcor.de> | 2015-03-01 23:50:17 +0100 |
|---|---|---|
| committer | reger <reger18@arcor.de> | 2015-03-01 23:50:17 +0100 |
| commit | 16bc267a3238cec0cdbf1346c0598e9bf788edf0 (patch) | |
| tree | a331b9c1c646625a19db2f80456c598931727c69 /test/net | |
| parent | a4629ad83be986587db24d1b5477219d0be0846a (diff) | |
add test case for snippet html encoding check
Diffstat (limited to 'test/net')
| -rw-r--r-- | test/net/yacy/search/snippet/TextSnippetTest.java | 35 |
1 files changed, 35 insertions, 0 deletions
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 </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");
+
+ // 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("<pre>")); // 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("<pre>")); // display text not to include unwanted html
+ assertTrue ("Query word not marked", sniptxt.contains("<b>test</b>")); // query word to be marked
+ }
}
|
