public virtual void DropsUnresolvableRelativeLinks() { String html = "<a href='/foo'>Link</a>"; String clean = iText.StyledXmlParser.Jsoup.Jsoup.Clean(html, Whitelist.Basic()); NUnit.Framework.Assert.AreEqual("<a rel=\"nofollow\">Link</a>", clean); }
public virtual void BasicBehaviourTest() { String h = "<div><p><a href='javascript:sendAllMoney()'>Dodgy</a> <A HREF='HTTP://nice.com/'>Nice</a></p><blockquote>Hello</blockquote>"; String cleanHtml = iText.StyledXmlParser.Jsoup.Jsoup.Clean(h, Whitelist.Basic()); NUnit.Framework.Assert.AreEqual("<p><a rel=\"nofollow\">Dodgy</a> <a href=\"http://nice.com/\" rel=\"nofollow\">Nice</a></p><blockquote>Hello</blockquote>" , TextUtil.StripNewlines(cleanHtml)); }
public virtual void TestRemoveTags() { String h = "<div><p><A HREF='HTTP://nice.com'>Nice</a></p><blockquote>Hello</blockquote>"; String cleanHtml = iText.StyledXmlParser.Jsoup.Jsoup.Clean(h, Whitelist.Basic().RemoveTags("a")); NUnit.Framework.Assert.AreEqual("<p>Nice</p><blockquote>Hello</blockquote>", TextUtil.StripNewlines(cleanHtml )); }
public virtual void TestRemoveProtocols() { String h = "<p>Contact me <a href='mailto:[email protected]'>here</a></p>"; String cleanHtml = iText.StyledXmlParser.Jsoup.Jsoup.Clean(h, Whitelist.Basic().RemoveProtocols("a", "href" , "ftp", "mailto")); NUnit.Framework.Assert.AreEqual("<p>Contact me <a rel=\"nofollow\">here</a></p>", TextUtil.StripNewlines(cleanHtml )); }
public virtual void TestRemoveAttributes() { String h = "<div><p>Nice</p><blockquote cite='http://example.com/quotations'>Hello</blockquote>"; String cleanHtml = iText.StyledXmlParser.Jsoup.Jsoup.Clean(h, Whitelist.Basic().RemoveAttributes("blockquote" , "cite")); NUnit.Framework.Assert.AreEqual("<p>Nice</p><blockquote>Hello</blockquote>", TextUtil.StripNewlines(cleanHtml )); }
public virtual void HandlesFramesets() { String dirty = "<html><head><script></script><noscript></noscript></head><frameset><frame src=\"foo\" /><frame src=\"foo\" /></frameset></html>"; String clean = iText.StyledXmlParser.Jsoup.Jsoup.Clean(dirty, Whitelist.Basic()); NUnit.Framework.Assert.AreEqual("", clean); // nothing good can come out of that Document dirtyDoc = iText.StyledXmlParser.Jsoup.Jsoup.Parse(dirty); Document cleanDoc = new Cleaner(Whitelist.Basic()).Clean(dirtyDoc); NUnit.Framework.Assert.IsFalse(cleanDoc == null); NUnit.Framework.Assert.AreEqual(0, cleanDoc.Body().ChildNodeSize()); }
public virtual void TestIsValid() { String ok = "<p>Test <b><a href='http://example.com/'>OK</a></b></p>"; String nok1 = "<p><script></script>Not <b>OK</b></p>"; String nok2 = "<p align=right>Test Not <b>OK</b></p>"; String nok3 = "<!-- comment --><p>Not OK</p>"; // comments and the like will be cleaned NUnit.Framework.Assert.IsTrue(iText.StyledXmlParser.Jsoup.Jsoup.IsValid(ok, Whitelist.Basic())); NUnit.Framework.Assert.IsFalse(iText.StyledXmlParser.Jsoup.Jsoup.IsValid(nok1, Whitelist.Basic())); NUnit.Framework.Assert.IsFalse(iText.StyledXmlParser.Jsoup.Jsoup.IsValid(nok2, Whitelist.Basic())); NUnit.Framework.Assert.IsFalse(iText.StyledXmlParser.Jsoup.Jsoup.IsValid(nok3, Whitelist.Basic())); }