[Mono-bugs] [Bug 647241] New: HttpContext.GetLocalResourceObject does not except root relative virtual paths

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Oct 16 20:22:55 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=647241

https://bugzilla.novell.com/show_bug.cgi?id=647241#c0


           Summary: HttpContext.GetLocalResourceObject does not except
                    root relative virtual paths
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: x86-64
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.Web
        AssignedTo: mhabersack at novell.com
        ReportedBy: Novell at meinersbur.de
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Description of Problem:

HttpContext.GetLocalResourceObject(string, string) raises an error if given a
path like "~/Default.aspx". The exception is:

System.ArgumentException: The specified virtualPath was not rooted.
  at System.Web.HttpContext.GetLocalResourceObject (System.String virtualPath,
System.String resourceKey, System.Globalization.CultureInfo culture) [0x0000b]
in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web/HttpContext.cs:533 
  at System.Web.HttpContext.GetLocalResourceObject (System.String virtualPath,
System.String resourceKey) [0x00000] in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web/HttpContext.cs:518 
  at N2.Utility.GetLocalResourceString (System.String resourceKey) [0x00010] in
/home/meinersbur/Downloads/n2cms_2.0_Source/src/N2/Utility.cs:314 
  at N2.Utility.GetResourceString (System.String classKey, System.String
resourceKey) [0x00006] in
/home/meinersbur/Downloads/n2cms_2.0_Source/src/N2/Utility.cs:336 
  at N2.Edit.ControlPanelLinkAttribute.AddTo (System.Web.UI.Control container,
N2.Edit.PluginContext context) [0x00032] in
/home/meinersbur/Downloads/n2cms_2.0_Source/src/N2/Edit/ControlPanelLinkAttribute.cs:63 
  at N2.Web.UI.WebControls.ControlPanel.AddPlugins (ControlPanelState state)
[0x0007c] in
/home/meinersbur/Downloads/n2cms_2.0_Source/src/N2/Web/UI/WebControls/ControlPanel.cs:208 
  at N2.Web.UI.WebControls.ControlPanel.CreateChildControls () [0x0004e] in
/home/meinersbur/Downloads/n2cms_2.0_Source/src/N2/Web/UI/WebControls/ControlPanel.cs:104 
  at System.Web.UI.Control.EnsureChildControls () [0x00041] in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web.UI/Control.cs:986 
  at N2.Web.UI.WebControls.ControlPanel.Page_InitComplete (System.Object
sender, System.EventArgs e) [0x00000] in
/home/meinersbur/Downloads/n2cms_2.0_Source/src/N2/Web/UI/WebControls/ControlPanel.cs:90 
  at System.Web.UI.Page.OnInitComplete (System.EventArgs e) [0x00029] in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web.UI/Page.cs:1955 
  at System.Web.UI.Page.InternalProcessRequest () [0x00192] in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web.UI/Page.cs:1421 
  at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context)
[0x0005b] in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web.UI/Page.cs:1260

Actual Results:
Exception thrown

Expected Results:
Mapping the root-relative virtual path to the expected resource

How often does this happen? 
Always

Additional Information:
Downloaded and patched newest version from GIT. Here is my solution:

diff --git a/mcs/class/System.Web/System.Web/HttpContext.cs
b/mcs/class/System.Web/System.Web/HttpContext.cs
index 5d9657d..7106d64 100644
--- a/mcs/class/System.Web/System.Web/HttpContext.cs
+++ b/mcs/class/System.Web/System.Web/HttpContext.cs
@@ -529,7 +529,7 @@ namespace System.Web

                public static object GetLocalResourceObject (string
virtualPath, string resourceKey, CultureInfo culture)
                {
-                       if (!VirtualPathUtility.IsAbsolute (virtualPath))
+                       if (!VirtualPathUtility.IsRooted (virtualPath))
                                throw new ArgumentException ("The specified
virtualPath was not rooted.");

                        return GetLocalObjectFromFactory (virtualPath,
resourceKey, culture);

Explanation:
Although the exception's message says that the path must be rooted, it demands
an absolute path. Hence, "~/" -- the root of the application -- is not allowed
here.

Later in the stack frame we get another error...

System.Web.VirtualPathUtility.GetDirectory (virtualPath="/", normalize=true) in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web/VirtualPathUtility.cs:107
System.Web.VirtualPathUtility.GetDirectory (virtualPath="~/") in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web/VirtualPathUtility.cs:92
System.Web.Compilation.DefaultResourceProvider.GetLocalResourcesAssembly () in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web.Compilation/DefaultResourceProvider.cs:127
System.Web.Compilation.DefaultResourceProvider.GetResourceManager () in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web.Compilation/DefaultResourceProvider.cs:148
System.Web.Compilation.DefaultResourceProvider.GetObject
(resourceKey="cpView.ToolTip", culture={de-DE}) in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web.Compilation/DefaultResourceProvider.cs:115
System.Web.HttpContext.GetLocalObjectFromFactory (virtualPath="~/",
resourceKey="cpView.ToolTip", culture={de-DE}) in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web/HttpContext.cs:527
System.Web.HttpContext.GetLocalResourceObject (virtualPath="~/",
resourceKey="cpView.ToolTip", culture={de-DE}) in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web/HttpContext.cs:535
System.Web.HttpContext.GetLocalResourceObject (virtualPath="~/",
resourceKey="cpView.ToolTip") in
/home/meinersbur/Desktop/mono/mcs/class/System.Web/System.Web/HttpContext.cs:518
N2.Utility.GetLocalResourceString (resourceKey="cpView.ToolTip") in
/home/meinersbur/Downloads/n2cms_2.0_Source/src/N2/Utility.cs:314

The Exception we get is a NullReferenceException at
GetLocalResourcesAssembly(path) because it receives null.


diff --git a/mcs/class/System.Web/System.Web/VirtualPathUtility.cs
b/mcs/class/System.Web/System.Web/VirtualPathUtility.cs
index a58a8fe..2af592e 100644
--- a/mcs/class/System.Web/System.Web/VirtualPathUtility.cs
+++ b/mcs/class/System.Web/System.Web/VirtualPathUtility.cs
@@ -104,7 +104,7 @@ namespace System.Web {
        internal static string GetDirectory (string virtualPath, bool
normalize)
        {
            if (normalize)
                virtualPath = Normalize (virtualPath);

            int vpLen = virtualPath.Length;
            if (IsAppRelative (virtualPath) && vpLen < 3) { // "~" or "~/"
                virtualPath = ToAbsolute (virtualPath);
                vpLen = virtualPath.Length;
                        }

                        if (vpLen == 1 && virtualPath [0] == '/') // "/"
-                               return null;
+                               return "/";

                        int last = virtualPath.LastIndexOf ('/', vpLen - 2,
vpLen - 2);
                        if (last > 0)
                return virtualPath.Substring (0, last + 1);
            else
                return "/";
        }


Explanation:
When this encounters the root directory "/", it surprisingly returns null, the
only case it does so, although "/" is a valid result as indicated by the last
statement.
The absolute path being "/" is a valid result. This happens when the file is in
the applications root directory and the ApplicationPath
(HttpRuntime.AppDomainAppVirtualPath) is serves the complete domain.
I noticed other code in mono that test's the functions result for null, so this
function should determine invalid results somehow different.

This is mainly a compatibility-to.Net issue since it works with Microsoft's
implementation.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list