Ejemplo n.º 1
0
        public void UnSafeXhtml_cleanses_Audio_element()
        {
            XDoc doc = XDocFactory.From("<doc><audio src=\"\" poster=\"\" onloadstart=\"\" onprogress=\"\" unsafe=\"\"></audio></doc>", MimeType.TEXT_XML);

            DekiScriptLibrary.ValidateXHtml(doc, false, true);
            Assert.AreEqual("<doc><audio src=\"\" onloadstart=\"\" onprogress=\"\"></audio></doc>", doc.ToString());
        }
Ejemplo n.º 2
0
        public void SafeXhtml_cleanses_Audio_src_attribute()
        {
            XDoc doc = XDocFactory.From("<doc><audio src=\"javascript://\" poster=\"javascript://\" autoplay=\"\" loop=\"\" controls=\"\"></audio></doc>", MimeType.TEXT_XML);

            DekiScriptLibrary.ValidateXHtml(doc, true, true);
            Assert.AreEqual("<doc><audio autoplay=\"\" loop=\"\" controls=\"\"></audio></doc>", doc.ToString());
        }
Ejemplo n.º 3
0
        public void UnSafeXhtml_cleanses_Video_with_sources()
        {
            XDoc doc = XDocFactory.From("<doc><video poster=\"\" onloadstart=\"\" onprogress=\"\"><source src=\"\" unsafe=\"\"/></video></doc>", MimeType.TEXT_XML);

            DekiScriptLibrary.ValidateXHtml(doc, false, true);
            Assert.AreEqual("<doc><video poster=\"\" onloadstart=\"\" onprogress=\"\"><source src=\"\" /></video></doc>", doc.ToString());
        }
Ejemplo n.º 4
0
        public void SafeXhtml_cleanses_Video_element()
        {
            XDoc doc = XDocFactory.From("<doc><video src=\"\" poster=\"\" autoplay=\"\" loop=\"\" controls=\"\" width=\"\" height=\"\" onloadstart=\"\" onprogress=\"\"></video></doc>", MimeType.TEXT_XML);

            DekiScriptLibrary.ValidateXHtml(doc, true, true);
            Assert.AreEqual("<doc><video src=\"\" poster=\"\" autoplay=\"\" loop=\"\" controls=\"\" width=\"\" height=\"\"></video></doc>", doc.ToString());
        }
Ejemplo n.º 5
0
        public override XDoc AsEmbeddableXml(bool safe)
        {
            XDoc result = Value;

            if (!Value.IsEmpty && !Value.HasName("html"))
            {
                result = new XDoc("html").Start("body").Add(Value).End();
                if (safe)
                {
                    foreach (XDoc body in result["body"])
                    {
                        DekiScriptLibrary.ValidateXHtml(body, true, true);
                    }
                }
            }
            return(result);
        }
        private XDoc ConvertToXml(bool safe)
        {
            if (!(_value is XDoc))
            {
                if (_value is DekiScriptString)
                {
                    // use the native value of the string literal
                    _value = new XDoc("html").Elem("head").Elem("body", ((DekiScriptString)_value).Value).Elem("tail");
                }
                else if (_value != null)
                {
                    // use contents of string builder or convert literal to string
                    _value = new XDoc("html").Elem("head").Elem("body", _value.ToString()).Elem("tail");
                }
                else
                {
                    // create an empty XML document
                    _value = new XDoc("html").Elem("head").Elem("body").Elem("tail");
                }
            }
            else
            {
                // make sure the document has <head> and <tail> elements
                XDoc doc = (XDoc)_value;

                // check if xml has the right form
                if (!doc.HasName("html"))
                {
                    doc = new XDoc("html").Start("body").Add(doc).End();
                    if (safe)
                    {
                        DekiScriptLibrary.ValidateXHtml(doc["body"], true, true);
                    }
                    _value = doc;
                }

                // check if all the necessary elements are in place
                bool foundHead = false;
                bool foundBody = false;
                bool foundTail = false;
                foreach (XmlNode node in doc.AsXmlNode.ChildNodes)
                {
                    if (node.NodeType == XmlNodeType.Element)
                    {
                        foundHead = foundHead || StringUtil.EqualsInvariant(node.LocalName, "head");
                        foundBody = foundBody || StringUtil.EqualsInvariant(node.LocalName, "body") && string.IsNullOrEmpty(((XmlElement)node).GetAttribute("target"));
                        foundTail = foundTail || StringUtil.EqualsInvariant(node.LocalName, "tail");
                    }
                    if (foundHead && foundTail && foundBody)
                    {
                        break;
                    }
                }
                if (!foundHead)
                {
                    doc.Elem("head");
                }
                if (!foundBody)
                {
                    doc.Elem("body");
                }
                if (!foundTail)
                {
                    doc.Elem("tail");
                }
            }
            return((XDoc)_value);
        }