2005-12-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 2 Dec 2005 19:01:47 +0000 (19:01 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 2 Dec 2005 19:01:47 +0000 (19:01 -0000)
* HttpHandlersSectionHandler.cs:
* HandlerFactoryConfiguration.cs: we need to use a copy of the parent
mappings, otherwise we may remove mappings from the parent. Fix a typo
when removing the item from the collection. Now LocateHandler searches
first for this configuration mappings and then for the parent ones.
Fixes (truly) bug #76842.

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

mcs/class/System.Web/System.Web.Configuration/ChangeLog
mcs/class/System.Web/System.Web.Configuration/HandlerFactoryConfiguration.cs
mcs/class/System.Web/System.Web.Configuration/HttpHandlersSectionHandler.cs

index 4a6900fe69020b8b9348c0d5e7c81a4cf943fb51..be326e5abcbe94280ba2cad1261b87b2f46e2916 100644 (file)
@@ -1,3 +1,12 @@
+2005-12-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * HttpHandlersSectionHandler.cs:
+       * HandlerFactoryConfiguration.cs: we need to use a copy of the parent
+       mappings, otherwise we may remove mappings from the parent. Fix a typo
+       when removing the item from the collection. Now LocateHandler searches
+       first for this configuration mappings and then for the parent ones.
+       Fixes (truly) bug #76842.
+
 2005-11-30 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * HandlerFactoryConfiguration.cs: my previous patch broke the
index 2ab166c95736f8affab7f9107e97222d2d7ea21a..353393af8e413e70588ca8499c8791d6c16a8335 100644 (file)
@@ -3,9 +3,10 @@
 //  
 //
 // Authors:
-//     Miguel de Icaza (miguel@novell.com
+//     Miguel de Icaza (miguel@novell.com)
+//     Gonzalo Paniagua Javier (gonzalo@novell.com)
 //
-// (C) 2002 Ximian, Inc (http://www.ximian.com)
+// (C) 2005 Novell, Inc (http://www.novell.com)
 //
 
 //
@@ -163,11 +164,18 @@ namespace System.Web.Configuration {
        class HandlerFactoryConfiguration {
                ArrayList handlers;
                HandlerFactoryConfiguration parent;
+               int parent_items;
+
                public HandlerFactoryConfiguration (HandlerFactoryConfiguration parent)
                {
                        this.parent = parent;
 
-                       handlers = new ArrayList ();
+                       if (parent != null) {
+                               handlers = new ArrayList (parent.handlers);
+                               parent_items = handlers.Count;
+                       } else {
+                               handlers = new ArrayList ();
+                       }
                }
 
                public void Clear ()
@@ -189,52 +197,51 @@ namespace System.Web.Configuration {
                        handlers.Add (new HttpHandler (verb, path, type_name, type));
                }
 
-               public HttpHandler Remove (string verb, string path)
+               public bool Remove (string verb, string path)
                {
-                       int top = handlers.Count;
-
-                       for (int i = 0; i < top; i++){
+                       for (int i = handlers.Count - 1; i >= 0; i--) {
                                HttpHandler handler = (HttpHandler) handlers [i];
 
                                if (verb == handler.OriginalVerb && path == handler.OriginalPath){
-                                       handlers.Remove (i);
-                                       return handler;
+                                       handlers.RemoveAt (i);
+                                       return true;
                                }
                        }
 
-                       if (parent != null)
-                               return parent.Remove (verb, path);
-
-                       return null;
+                       return false;
                }
 
                public object LocateHandler (string verb, string filepath)
                {
-                       int top = handlers.Count;
-
-                       for (int i = 0; i < top; i++){
-                               HttpHandler handler = (HttpHandler) handlers [i];
-
-                               if (handler.Verbs == null){
-                                       if (handler.PathMatches (filepath))
-                                               return handler.GetHandlerInstance ();
-                                       continue;
-                               }
-
-                               string [] verbs = handler.Verbs;
-                               for (int j = verbs.Length; j > 0; ){
-                                       j--;
-                                       if (verbs [j] != verb)
+                       int start, end;
+                       int count = handlers.Count;
+                       for (int k = 0; k < 2; k++) {
+                               // First iteration searches for the mapping in the items added to this
+                               // instance. The second one searches through the parent items if any.
+                               start = (k == 0) ? parent_items : 0;
+                               end = (k == 0) ? count : parent_items;
+                               for (int i = start; i < end; i++) {
+                                       HttpHandler handler = (HttpHandler) handlers [i];
+
+                                       if (handler.Verbs == null){
+                                               if (handler.PathMatches (filepath))
+                                                       return handler.GetHandlerInstance ();
                                                continue;
-                                       if (handler.PathMatches (filepath))
-                                               return handler.GetHandlerInstance ();
+                                       }
+
+                                       string [] verbs = handler.Verbs;
+                                       for (int j = verbs.Length; j > 0; ){
+                                               j--;
+                                               if (verbs [j] != verb)
+                                                       continue;
+                                               if (handler.PathMatches (filepath))
+                                                       return handler.GetHandlerInstance ();
+                                       }
                                }
                        }
 
-                       if (parent != null)
-                               return parent.LocateHandler (verb, filepath);
-                       else
-                               return null;
+                       return null;
                }
        }
 }
+
index b19b7beeff3ab7ac23b8fe60f2b959e8b444d74e..ac9af341c342db25e2d6cf4146f57b27cf50c763 100644 (file)
@@ -92,7 +92,7 @@ namespace System.Web.Configuration
                                        if (child.Attributes != null && child.Attributes.Count != 0)
                                                HandlersUtil.ThrowException ("Unrecognized attribute", child);
 
-                                       if (validate && mapper.Remove (verb, path) == null)
+                                       if (validate && false == mapper.Remove (verb, path))
                                                HandlersUtil.ThrowException ("There's no mapping to remove", child);
                                        
                                        continue;