2009-06-30 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / System.Security / SecurityElement.cs
index ddd46fca3fc2f9fbb496bb193fefe672c84b30b1..7fd209bd6b7aa0ce3444f55cf6364a9e8df7d12c 100644 (file)
@@ -58,7 +58,7 @@ namespace System.Security {
                                        throw new ArgumentException (Locale.GetText ("Invalid XML attribute value") + ": " + value);
 
                                _name = name;
-                               _value = value;
+                               _value = SecurityElement.Unescape (value);
                        }
 
                        public string Name {
@@ -194,7 +194,7 @@ namespace System.Security {
                                                        Locale.GetText ("Invalid XML string")
                                                        + ": " + value);
                                }
-                               text = value;
+                               text = Unescape (value);
                        }
                }
 
@@ -316,6 +316,22 @@ namespace System.Security {
                        return sb.ToString ();
                }
 
+               private static string Unescape (string str)
+               {
+                       StringBuilder sb;
+
+                       if (str == null)
+                               return null;
+
+                       sb = new StringBuilder (str);
+                       sb.Replace ("&lt;", "<");
+                       sb.Replace ("&gt;", ">");
+                       sb.Replace ("&amp;", "&");
+                       sb.Replace ("&quot;", "\"");
+                       sb.Replace ("&apos;", "'");
+                       return sb.ToString ();
+               }
+
 #if NET_2_0
                public
 #else
@@ -348,14 +364,14 @@ namespace System.Security {
                        return value != null && value.IndexOfAny (invalid_attr_value_chars) == -1;
                }
 
-               public static bool IsValidTag (string value)
+               public static bool IsValidTag (string tag)
                {
-                       return value != null && value.IndexOfAny (invalid_tag_chars) == -1;
+                       return tag != null && tag.IndexOfAny (invalid_tag_chars) == -1;
                }
 
-               public static bool IsValidText (string value)
+               public static bool IsValidText (string text)
                {
-                       return value != null && value.IndexOfAny (invalid_text_chars) == -1;
+                       return text != null && text.IndexOfAny (invalid_text_chars) == -1;
                }
 
                public SecurityElement SearchForChildByTag (string tag) 
@@ -423,7 +439,7 @@ namespace System.Security {
 #endif
                                        s.Append (sa.Name)
                                         .Append ("=\"")
-                                        .Append (sa.Value)
+                                        .Append (Escape (sa.Value))
                                         .Append ("\"");
                                        if (i != attributes.Count - 1)
                                                s.Append (Environment.NewLine);
@@ -434,7 +450,7 @@ namespace System.Security {
                            (children == null || children.Count == 0))
                                s.Append ("/>").Append (Environment.NewLine);
                        else {
-                               s.Append (">").Append (text);
+                               s.Append (">").Append (Escape (text));
                                if (children != null) {
                                        s.Append (Environment.NewLine);
                                        foreach (SecurityElement child in children) {