예제 #1
0
        /// <summary> Go through the <common-attributes> section of the policy file.</summary>
        /// <param name="root">Top level of <common-attributes>
        /// </param>
        /// <returns> An ArrayList of Attribute objects.
        /// </returns>
        private Hashtable parseCommonAttributes(XmlNode commonAttributeListNode)
        {
            XmlNodeList commonAttributeNodes = commonAttributeListNode.SelectNodes("attribute");
            Hashtable commonAttributes = new Hashtable();

            foreach (XmlNode node in commonAttributeNodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    /*DEFAULT_ONINVALID seems to have been removed from common attributes.  Do we need this code?*/
                    String onInvalid = (node.Attributes["onInvalid"] == null ? null : node.Attributes["onInvalid"].Value);
                    String name = (node.Attributes["name"] == null ? null : node.Attributes["name"].Value);
                    org.owasp.validator.html.model.Attribute attribute = new org.owasp.validator.html.model.Attribute(name);
                    attribute.Description = (node.Attributes["description"] == null ? null : node.Attributes["description"].Value);
                    if (onInvalid != null && onInvalid.Length > 0)
                    {
                        attribute.OnInvalid = onInvalid;
                    }
                    else
                    {
                        attribute.OnInvalid = DEFAULT_ONINVALID;
                    }

                    XmlNodeList regExpListNode = node.SelectNodes("regexp-list");
                    if (regExpListNode != null && regExpListNode.Count > 0)
                    {
                        XmlNodeList regExpList = regExpListNode[0].SelectNodes("regexp");
                        foreach (XmlNode regExpNode in regExpList)
                        {
                            string regExpName = (regExpNode.Attributes["name"] == null ? null : regExpNode.Attributes["name"].Value);
                            string value = (regExpNode.Attributes["value"] == null ? null : regExpNode.Attributes["value"].Value);
                            //TODO: java version uses "Pattern" class to hold regular expressions.  I'm storing them as strings below
                            //find out if I need an equiv to pattern
                            if (regExpName != null && regExpName.Length > 0)
                            {
                                attribute.addAllowedRegExp(getRegularExpression(regExpName).ToString());
                            }
                            else
                            {
                                attribute.addAllowedRegExp(REGEXP_BEGIN + value + REGEXP_END);
                            }
                        }
                    }
                    XmlNode literalListNode = node.SelectNodes("literal-list")[0];
                    if (literalListNode != null)
                    {
                        XmlNodeList literalNodes = literalListNode.SelectNodes("literal");
                        foreach (XmlNode literalNode in literalNodes)
                        {
                            string value = (literalNode.Attributes["value"] == null ? null : literalNode.Attributes["value"].Value);
                            if (value != null && value.Length > 0)
                            {
                                attribute.addAllowedValue(value);
                            }
                            else if (literalNode.Value != null)
                            {
                                attribute.addAllowedValue(literalNode.Value);
                            }
                        }
                    }
                    commonAttributes.Add(name, attribute);
                }
            }
            return commonAttributes;
        }
예제 #2
0
        /// <summary> Go through the <common-attributes> section of the policy file.</summary>
        /// <param name="root">Top level of <common-attributes>
        /// </param>
        /// <returns> An ArrayList of Attribute objects.
        /// </returns>
        private Hashtable parseCommonAttributes(XmlNode commonAttributeListNode)
        {
            XmlNodeList commonAttributeNodes = commonAttributeListNode.SelectNodes("attribute");
            Hashtable   commonAttributes     = new Hashtable();

            foreach (XmlNode node in commonAttributeNodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    /*DEFAULT_ONINVALID seems to have been removed from common attributes.  Do we need this code?*/
                    String onInvalid = (node.Attributes["onInvalid"] == null ? null : node.Attributes["onInvalid"].Value);
                    String name      = (node.Attributes["name"] == null ? null : node.Attributes["name"].Value);
                    org.owasp.validator.html.model.Attribute attribute = new org.owasp.validator.html.model.Attribute(name);
                    attribute.Description = (node.Attributes["description"] == null ? null : node.Attributes["description"].Value);
                    if (onInvalid != null && onInvalid.Length > 0)
                    {
                        attribute.OnInvalid = onInvalid;
                    }
                    else
                    {
                        attribute.OnInvalid = DEFAULT_ONINVALID;
                    }

                    XmlNodeList regExpListNode = node.SelectNodes("regexp-list");
                    if (regExpListNode != null && regExpListNode.Count > 0)
                    {
                        XmlNodeList regExpList = regExpListNode[0].SelectNodes("regexp");
                        foreach (XmlNode regExpNode in regExpList)
                        {
                            string regExpName = (regExpNode.Attributes["name"] == null ? null : regExpNode.Attributes["name"].Value);
                            string value      = (regExpNode.Attributes["value"] == null ? null : regExpNode.Attributes["value"].Value);
                            //TODO: java version uses "Pattern" class to hold regular expressions.  I'm storing them as strings below
                            //find out if I need an equiv to pattern
                            if (regExpName != null && regExpName.Length > 0)
                            {
                                attribute.addAllowedRegExp(getRegularExpression(regExpName).ToString());
                            }
                            else
                            {
                                attribute.addAllowedRegExp(REGEXP_BEGIN + value + REGEXP_END);
                            }
                        }
                    }
                    XmlNode literalListNode = node.SelectNodes("literal-list")[0];
                    if (literalListNode != null)
                    {
                        XmlNodeList literalNodes = literalListNode.SelectNodes("literal");
                        foreach (XmlNode literalNode in literalNodes)
                        {
                            string value = (literalNode.Attributes["value"] == null ? null : literalNode.Attributes["value"].Value);
                            if (value != null && value.Length > 0)
                            {
                                attribute.addAllowedValue(value);
                            }
                            else if (literalNode.Value != null)
                            {
                                attribute.addAllowedValue(literalNode.Value);
                            }
                        }
                    }
                    commonAttributes.Add(name, attribute);
                }
            }
            return(commonAttributes);
        }