Beispiel #1
0
        public void TestBlacklistedTags()
        {
            var config   = new MarkupSanity.SanitizeConfigurations();
            var actual   = "<b>sample text</b>".SanitizeHtml(config);
            var expected = "<b>sample text</b>";

            Assert.AreEqual(expected, actual);

            config.CustomBlacklistedTags = new List <String>()
            {
                "b"
            };

            actual   = "<b>sample text</b>".SanitizeHtml(config);
            expected = "";
            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        public void TrySanitizeFunction()
        {
            var    config = new MarkupSanity.SanitizeConfigurations();
            var    actual = "<b>sample text</b>";
            String outVal;

            Boolean wasCleaned = actual.TrySanitizeHtml(config, out outVal);

            Assert.AreEqual("<b>sample text</b>", outVal);
            Assert.AreEqual(true, wasCleaned);


            config.CustomBlacklistedTags = new List <String>()
            {
                "b"
            };
            wasCleaned = actual.TrySanitizeHtml(config, out outVal);

            Assert.AreEqual("", outVal);
            Assert.AreEqual(false, wasCleaned);
        }
Beispiel #3
0
        public void TestCustomConfigurationsParamater()
        {
            var actual   = "<codeblock>String s = 'use global here';</codeblock>".SanitizeHtml();
            var expected = "";

            Assert.AreEqual(expected, actual);

            var configs = new MarkupSanity.SanitizeConfigurations();

            configs.CustomWhitelistedTags = new List <String>()
            {
                "codeblock"
            };

            actual   = "<codeblock>String s = 'use custom configs here';</codeblock>".SanitizeHtml(configs);
            expected = "<codeblock>String s = 'use custom configs here';</codeblock>";
            Assert.AreEqual(expected, actual);

            actual   = "<codeblock>String s = 'use global again here';</codeblock>".SanitizeHtml();
            expected = "";
            Assert.AreEqual(expected, actual);
        }