Пример #1
0
        public XmlAttribute(XmlNodeName name, string value)
        {
            if (!SecurityElement.IsValidAttributeValue(value))
            {
                throw new ArgumentException();
            }

            this.Name  = name;
            this.Value = value;
        }
Пример #2
0
 public void IsValidAttributeValue()
 {
     Assert.True(SecurityElement.IsValidAttributeValue("x x"));
     Assert.False(SecurityElement.IsValidAttributeValue("x<x"));
     Assert.False(SecurityElement.IsValidAttributeValue("x>x"));
     Assert.False(SecurityElement.IsValidAttributeValue("x\"x"));
     Assert.True(SecurityElement.IsValidAttributeValue("x'x"));
     Assert.True(SecurityElement.IsValidAttributeValue("x&x"));
     Assert.False(SecurityElement.IsValidAttributeValue(null));
     Assert.True(SecurityElement.IsValidAttributeValue(string.Empty));
 }
 public void IsValidAttributeValue()
 {
     Assert.IsTrue(SecurityElement.IsValidAttributeValue("x x"), "#1");
     Assert.IsFalse(SecurityElement.IsValidAttributeValue("x<x"), "#2");
     Assert.IsFalse(SecurityElement.IsValidAttributeValue("x>x"), "#3");
     Assert.IsFalse(SecurityElement.IsValidAttributeValue("x\"x"), "#4");
     Assert.IsTrue(SecurityElement.IsValidAttributeValue("x'x"), "#5");
     Assert.IsTrue(SecurityElement.IsValidAttributeValue("x&x"), "#6");
     Assert.IsFalse(SecurityElement.IsValidAttributeValue(null), "#7");
     Assert.IsTrue(SecurityElement.IsValidAttributeValue(string.Empty), "#8");
 }
Пример #4
0
        public void WriteAttribute(XmlNodeName name, string value)
        {
            if (!SecurityElement.IsValidAttributeValue(value))
            {
                throw new ArgumentException();
            }

            if (!_needCloseElementStart)
            {
                throw new InvalidOperationException();
            }

            this.Write(" ", name.ToString(), "=\"", value, "\"");
        }
Пример #5
0
 // Add an attribute to the specified security element.
 private static SecurityElement AddAttribute(
     SecurityElement xmlElement,
     string attributeName,
     string attributeValue)
 {
     if (xmlElement != null)
     {
         // Verify that the attribute name and value are valid XML formats.
         if (SecurityElement.IsValidAttributeName(attributeName) &&
             SecurityElement.IsValidAttributeValue(attributeValue))
         {
             // Add the attribute to the security element.
             xmlElement.AddAttribute(attributeName, attributeValue);
         }
     }
     return(xmlElement);
 }
Пример #6
0
    // Test the valid string testing operators.
    public void TestSecurityElementValidStrings()
    {
        Assert("ValidAttrName (1)",
               !SecurityElement.IsValidAttributeName(null));
        Assert("ValidAttrName (2)",
               !SecurityElement.IsValidAttributeName(""));
        Assert("ValidAttrName (3)",
               !SecurityElement.IsValidAttributeName("a<b"));
        Assert("ValidAttrName (4)",
               !SecurityElement.IsValidAttributeName("a>b"));
        Assert("ValidAttrName (5)",
               !SecurityElement.IsValidAttributeName("&amp;"));
        Assert("ValidAttrName (6)",
               !SecurityElement.IsValidAttributeName(" "));
        Assert("ValidAttrName (7)",
               SecurityElement.IsValidAttributeName("fooBar"));
        Assert("ValidAttrName (8)",
               SecurityElement.IsValidAttributeName("123"));

        Assert("ValidAttrValue (1)",
               !SecurityElement.IsValidAttributeValue(null));
        Assert("ValidAttrValue (2)",
               SecurityElement.IsValidAttributeValue(""));
        Assert("ValidAttrValue (3)",
               !SecurityElement.IsValidAttributeValue("a<b"));
        Assert("ValidAttrValue (4)",
               !SecurityElement.IsValidAttributeValue("a>b"));
        Assert("ValidAttrValue (5)",
               SecurityElement.IsValidAttributeValue("&amp;"));
        Assert("ValidAttrValue (6)",
               SecurityElement.IsValidAttributeValue(" "));
        Assert("ValidAttrValue (7)",
               SecurityElement.IsValidAttributeValue("fooBar"));
        Assert("ValidAttrValue (8)",
               SecurityElement.IsValidAttributeValue("123"));
        Assert("ValidAttrValue (9)",
               !SecurityElement.IsValidAttributeValue("\""));

        Assert("ValidTag (1)",
               !SecurityElement.IsValidTag(null));
        Assert("ValidTag (2)",
               !SecurityElement.IsValidTag(""));
        Assert("ValidTag (3)",
               !SecurityElement.IsValidTag("a<b"));
        Assert("ValidTag (4)",
               !SecurityElement.IsValidTag("a>b"));
        Assert("ValidTag (5)",
               !SecurityElement.IsValidTag("&amp;"));
        Assert("ValidTag (6)",
               !SecurityElement.IsValidTag(" "));
        Assert("ValidTag (7)",
               SecurityElement.IsValidTag("fooBar"));
        Assert("ValidTag (8)",
               SecurityElement.IsValidTag("123"));

        Assert("ValidText (1)",
               !SecurityElement.IsValidText(null));
        Assert("ValidText (2)",
               SecurityElement.IsValidText(""));
        Assert("ValidText (3)",
               !SecurityElement.IsValidText("a<b"));
        Assert("ValidText (4)",
               !SecurityElement.IsValidText("a>b"));
        Assert("ValidText (5)",
               SecurityElement.IsValidText("&amp;"));
        Assert("ValidText (6)",
               SecurityElement.IsValidText(" "));
        Assert("ValidText (7)",
               SecurityElement.IsValidText("fooBar"));
        Assert("ValidText (8)",
               SecurityElement.IsValidText("123"));
        Assert("ValidText (9)",
               SecurityElement.IsValidText("\""));
    }