public void preservesRelatedLinksIfConfigured()
        {
            string html  = "<a href='/foo'>Link</a><img src='/bar'> <img src='javascript:alert()'>";
            string clean = NSoupClient.Clean(html, "http://example.com/", Whitelist.BasicWithImages.PreserveRelativeLinks(true));

            Assert.AreEqual("<a href=\"/foo\" rel=\"nofollow\">Link</a>\n<img src=\"/bar\" /> \n<img />", clean);
        }
        public void supplyOutputSettings()
        {
            // test that one can override the default document output settings
            OutputSettings os = new OutputSettings();

            os.PrettyPrint(false);
            os.SetEscapeMode(Entities.EscapeMode.Extended);

            string html       = "<div><p>&bernou;</p></div>";
            string customOut  = NSoupClient.Clean(html, "http://foo.com/", Whitelist.Relaxed, os);
            string defaultOut = NSoupClient.Clean(html, "http://foo.com/", Whitelist.Relaxed);

            Assert.AreNotSame(defaultOut, customOut);

            Assert.AreEqual("<div><p>&bernou;</p></div>", customOut);
            Assert.AreEqual("<div>\n" +
                            " <p>ℬ</p>\n" +
                            "</div>", defaultOut);

            os.SetEncoding(Encoding.ASCII);
            os.SetEscapeMode(Entities.EscapeMode.Base);
            String customOut2 = NSoupClient.Clean(html, "http://foo.com/", Whitelist.Relaxed, os);

            Assert.AreEqual("<div><p>&#8492;</p></div>", customOut2);
        }
        public void resolvesRelativeLinks()
        {
            String html  = "<a href='/foo'>Link</a><img src='/bar'>";
            String clean = NSoupClient.Clean(html, "http://example.com/", Whitelist.BasicWithImages);

            Assert.AreEqual("<a href=\"http://example.com/foo\" rel=\"nofollow\">Link</a>\n<img src=\"http://example.com/bar\" />", clean);
        }
        public void cleansInternationalTextNoEscaping()
        {
            var outputSettings = new OutputSettings();

            outputSettings = (OutputSettings)outputSettings.Clone();
            outputSettings.EscapeMode.GetMap().Clear();
            var result = NSoupClient.Clean("׀¿ׁ€׀¸׀²׀µׁ‚", "", Whitelist.None, outputSettings);

            Assert.AreEqual("׀¿ׁ€׀¸׀²׀µׁ‚", result);
        }
        public void addsTagOnAttributesIfNotSet()
        {
            String    html      = "<p class='foo' src='bar'>One</p>";
            Whitelist whitelist = new Whitelist()
                                  .AddAttributes("p", "class");
            // ^^ whitelist does not have explicit tag add for p, inferred from add attributes.
            String clean = NSoupClient.Clean(html, whitelist);

            Assert.AreEqual("<p class=\"foo\">One</p>", clean);
        }
        public void handlesCustomProtocols()
        {
            String html    = "<img src='cid:12345' /> <img src='data:gzzt' />";
            String dropped = NSoupClient.Clean(html, Whitelist.BasicWithImages);

            Assert.AreEqual("<img /> \n<img />", dropped);

            String preserved = NSoupClient.Clean(html, Whitelist.BasicWithImages.AddProtocols("img", "src", "cid", "data"));

            Assert.AreEqual("<img src=\"cid:12345\" /> \n<img src=\"data:gzzt\" />", preserved);
        }
        public void handlesAllPseudoTag()
        {
            String    html      = "<p class='foo' src='bar'><a class='qux'>link</a></p>";
            Whitelist whitelist = new Whitelist()
                                  .AddAttributes(":all", "class")
                                  .AddAttributes("p", "style")
                                  .AddTags("p", "a");

            String clean = NSoupClient.Clean(html, whitelist);

            Assert.AreEqual("<p class=\"foo\"><a class=\"qux\">link</a></p>", clean);
        }
        public void handlesFramesets()
        {
            String dirty = "<html><head><script></script><noscript></noscript></head><frameset><frame src=\"foo\" /><frame src=\"foo\" /></frameset></html>";
            String clean = NSoupClient.Clean(dirty, Whitelist.Basic);

            Assert.AreEqual("", clean); // nothing good can come out of that

            Document dirtyDoc = NSoupClient.Parse(dirty);
            Document cleanDoc = new Cleaner(Whitelist.Basic).Clean(dirtyDoc);

            Assert.IsFalse(cleanDoc == null);
            Assert.AreEqual(0, cleanDoc.Body.ChildNodes.Count);
        }
        public void cleansInternationalText()
        {
            var result = NSoupClient.Clean("׀¿ׁ€׀¸׀²׀µׁ‚", Whitelist.None);

            Assert.AreEqual("׀&iquest;ׁ€׀&cedil;׀&sup2;׀&micro;ׁ‚", result);
        }
Ejemplo n.º 10
0
 public void cleansInternationalText()
 {
     Assert.AreEqual("׀¿ׁ€׀¸׀²׀µׁ‚", NSoupClient.Clean("׀¿ׁ€׀¸׀²׀µׁ‚", Whitelist.None));
 }