From 7510c8e3d4271f3f9572bddd82fedeeca7ae777c Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Fri, 2 Dec 2005 19:01:47 +0000 Subject: [PATCH] 2005-12-02 Gonzalo Paniagua Javier * 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 --- .../System.Web.Configuration/ChangeLog | 9 +++ .../HandlerFactoryConfiguration.cs | 75 ++++++++++--------- .../HttpHandlersSectionHandler.cs | 2 +- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/mcs/class/System.Web/System.Web.Configuration/ChangeLog b/mcs/class/System.Web/System.Web.Configuration/ChangeLog index 4a6900fe690..be326e5abcb 100644 --- a/mcs/class/System.Web/System.Web.Configuration/ChangeLog +++ b/mcs/class/System.Web/System.Web.Configuration/ChangeLog @@ -1,3 +1,12 @@ +2005-12-02 Gonzalo Paniagua Javier + + * 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 * HandlerFactoryConfiguration.cs: my previous patch broke the diff --git a/mcs/class/System.Web/System.Web.Configuration/HandlerFactoryConfiguration.cs b/mcs/class/System.Web/System.Web.Configuration/HandlerFactoryConfiguration.cs index 2ab166c9573..353393af8e4 100644 --- a/mcs/class/System.Web/System.Web.Configuration/HandlerFactoryConfiguration.cs +++ b/mcs/class/System.Web/System.Web.Configuration/HandlerFactoryConfiguration.cs @@ -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; } } } + diff --git a/mcs/class/System.Web/System.Web.Configuration/HttpHandlersSectionHandler.cs b/mcs/class/System.Web/System.Web.Configuration/HttpHandlersSectionHandler.cs index b19b7beeff3..ac9af341c34 100644 --- a/mcs/class/System.Web/System.Web.Configuration/HttpHandlersSectionHandler.cs +++ b/mcs/class/System.Web/System.Web.Configuration/HttpHandlersSectionHandler.cs @@ -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; -- 2.25.1