2010-02-12 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Fri, 12 Feb 2010 12:16:08 +0000 (12:16 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Fri, 12 Feb 2010 12:16:08 +0000 (12:16 -0000)
* CustomizableLocalFileSettingsProvider.cs: The name of the child
class of Settings should be 'normalized' by replacing the chars that
are invalid in a xml element name with their corresponding hexadecimal
values. This is specially visible when using classes container in
other classes.
Fixes #471289.

svn path=/trunk/mcs/; revision=151607

mcs/class/System/System.Configuration/ChangeLog
mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs

index ca61bf66526ca90502962afdf48608a14b3f712d..bfd20ada9c186a1eda6945d35d5b31aeaacc9059 100644 (file)
@@ -1,3 +1,12 @@
+2010-02-12 Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+       * CustomizableLocalFileSettingsProvider.cs: The name of the child
+       class of Settings should be 'normalized' by replacing the chars that
+       are invalid in a xml element name with their corresponding hexadecimal
+       values. This is specially visible when using classes container in
+       other classes.
+       Fixes #471289.
+
 2009-08-31 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * CustomizableFileSettingsProvider.cs: reset the property value
index a1ffe5405f3bf3a6662838a025ca3051340e3ba5..77d9f3488ac4a9502675a33db57c2721e0b7e0be 100644 (file)
@@ -613,7 +613,8 @@ namespace System.Configuration
                                config.SectionGroups.Add ("userSettings", userGroup);
                                ApplicationSettingsBase asb = context.CurrentSettings;
                                ClientSettingsSection cs = new ClientSettingsSection ();
-                               userGroup.Sections.Add ((asb != null ? asb.GetType () : typeof (ApplicationSettingsBase)).FullName, cs);
+                               string class_name = NormalizeInvalidXmlChars ((asb != null ? asb.GetType () : typeof (ApplicationSettingsBase)).FullName);
+                               userGroup.Sections.Add (class_name, cs);
                        }
 
                        bool hasChanges = false;
@@ -690,6 +691,20 @@ namespace System.Configuration
 #endif
                }
 
+               // NOTE: We should add here all the chars that are valid in a name of a class (Ecma-wise),
+               // but invalid in an xml element name, and provide a better impl if we get too many of them.
+               string NormalizeInvalidXmlChars (string str)
+               {
+                       char [] invalid_chars = new char [] { '+' };
+
+                       if (str == null || str.IndexOfAny (invalid_chars) == -1)
+                               return str;
+
+                       // Replace with its hexadecimal values.
+                       str = str.Replace ("+", "_x002B_");
+                       return str;
+               }
+
                private void LoadPropertyValue (SettingsPropertyCollection collection, SettingElement element, bool allowOverwrite)
                {
                        SettingsProperty prop = collection [element.Name];
@@ -772,6 +787,7 @@ namespace System.Configuration
                        if (values == null) {
                                values = new SettingsPropertyValueCollection ();
                                string groupName = context ["GroupName"] as string;
+                               groupName = NormalizeInvalidXmlChars (groupName); // we likely saved the element removing the non valid xml chars.
                                LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false, groupName);
                                LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false, groupName);