From 696773bd62ffbd779ef85776502f3d2e88d572b2 Mon Sep 17 00:00:00 2001 From: Igor Zelmanovich Date: Thu, 15 Mar 2007 17:48:42 +0000 Subject: [PATCH] 2007-03-15 Igor Zelmanovich * HttpRequest.cs: fixed MapPath () method. svn path=/trunk/mcs/; revision=74403 --- .../System.Web.Hosting/SimpleWorkerRequest.cs | 2 ++ mcs/class/System.Web/System.Web/ChangeLog | 4 ++++ mcs/class/System.Web/System.Web/HttpRequest.cs | 17 ++++++++++++++--- .../System.Web/Test/System.Web/HttpRequestTest.cs | 18 ++++++++---------- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/mcs/class/System.Web/System.Web.Hosting/SimpleWorkerRequest.cs b/mcs/class/System.Web/System.Web.Hosting/SimpleWorkerRequest.cs index c79217479fa..f58209bcbfc 100644 --- a/mcs/class/System.Web/System.Web.Hosting/SimpleWorkerRequest.cs +++ b/mcs/class/System.Web/System.Web.Hosting/SimpleWorkerRequest.cs @@ -264,6 +264,8 @@ namespace System.Web.Hosting { string rest = path.Substring (app_virtual_dir.Length); if (rest.Length > 0 && rest [0] == '/') rest = rest.Substring (1); + if (Path.DirectorySeparatorChar != '/') // for windows suport + rest = rest.Replace ('/', Path.DirectorySeparatorChar); return Path.Combine (app_physical_dir, rest); } diff --git a/mcs/class/System.Web/System.Web/ChangeLog b/mcs/class/System.Web/System.Web/ChangeLog index 8ca024a76a9..ec26b161eb0 100644 --- a/mcs/class/System.Web/System.Web/ChangeLog +++ b/mcs/class/System.Web/System.Web/ChangeLog @@ -1,5 +1,9 @@ 2007-03-15 Igor Zelmanovich + * HttpRequest.cs: fixed MapPath () method. + +2007-03-15 Igor Zelmanovich + * VirtualPathUtility.cs: fixed ToAbsolute() method. 2007-03-15 Igor Zelmanovich diff --git a/mcs/class/System.Web/System.Web/HttpRequest.cs b/mcs/class/System.Web/System.Web/HttpRequest.cs index 1f78568eb16..50f3b7915ba 100644 --- a/mcs/class/System.Web/System.Web/HttpRequest.cs +++ b/mcs/class/System.Web/System.Web/HttpRequest.cs @@ -1115,9 +1115,13 @@ namespace System.Web { String.Format ("MapPath: Invalid path '{0}', only virtual paths are accepted", virtualPath)); string appVirtualPath = HttpRuntime.AppDomainAppVirtualPath; - if (baseVirtualDir == null) - baseVirtualDir = appVirtualPath; - virtualPath = UrlUtils.Combine (baseVirtualDir, virtualPath); + + if (!VirtualPathUtility.IsRooted (virtualPath)) { + if (StrUtils.IsNullOrEmpty (baseVirtualDir)) + baseVirtualDir = appVirtualPath; + virtualPath = VirtualPathUtility.Combine (VirtualPathUtility.AppendTrailingSlash (baseVirtualDir), virtualPath); + } + virtualPath = VirtualPathUtility.ToAbsolute (virtualPath); if (!allowCrossAppMapping){ if (!StrUtils.StartsWith (virtualPath, appVirtualPath, true)) @@ -1125,7 +1129,14 @@ namespace System.Web { if (appVirtualPath.Length > 1 && virtualPath.Length > 1 && virtualPath [0] != '/') throw new HttpException ("MapPath: Mapping across applications not allowed"); } +#if TARGET_JVM return worker_request.MapPath (virtualPath); +#else + string path = worker_request.MapPath (virtualPath); + if (virtualPath [virtualPath.Length - 1] != '/' && path [path.Length - 1] == System.IO.Path.DirectorySeparatorChar) + path = path.TrimEnd (System.IO.Path.DirectorySeparatorChar); + return path; +#endif } public void SaveAs (string filename, bool includeHeaders) diff --git a/mcs/class/System.Web/Test/System.Web/HttpRequestTest.cs b/mcs/class/System.Web/Test/System.Web/HttpRequestTest.cs index d64f99bb1e6..8359c80f4c1 100644 --- a/mcs/class/System.Web/Test/System.Web/HttpRequestTest.cs +++ b/mcs/class/System.Web/Test/System.Web/HttpRequestTest.cs @@ -147,16 +147,9 @@ namespace MonoTests.System.Web { } [Test] -#if TARGET_JVM //BUG #6500 -#endif - [Category ("NotWorking")] [Category ("NunitWeb")] public void Test_PhysicalApplicationPath () { - // - // This does not work because of the WebTest.Run creates a new Web.config - // WebTest must be fixed. - // WebTest t = new WebTest (new HandlerInvoker (new HandlerDelegate ( PhysicalApplicationPathDelegate))); t.Run (); @@ -172,9 +165,6 @@ namespace MonoTests.System.Web { [Test] [Category ("NunitWeb")] -//#if TARGET_JVM //BUG #6500 - [Category ("NotWorking")] -//#endif public void Test_MapPath () { WebTest t = new WebTest (new HandlerInvoker (new HandlerDelegate ( @@ -187,6 +177,7 @@ namespace MonoTests.System.Web { HttpRequest r = HttpContext.Current.Request; string appBase = r.PhysicalApplicationPath.TrimEnd (Path.DirectorySeparatorChar); Assert.AreEqual (appBase, r.MapPath ("~"), "test1"); + Assert.AreEqual (appBase + Path.DirectorySeparatorChar, r.MapPath ("~/"), "test1"); Assert.AreEqual (appBase, r.MapPath ("/NunitWeb"), "test1.1"); Assert.AreEqual (Path.Combine (appBase, "Web.config"), r.MapPath ("Web.config"), "test2"); @@ -202,6 +193,13 @@ namespace MonoTests.System.Web { r.MapPath ("Web.config", "/NunitWeb", false), "test7"); Assert.AreEqual (Path.Combine (appBase, "Web.config"), r.MapPath ("/NunitWeb/Web.config", "/NunitWeb", false), "test8"); + + Assert.AreEqual (Path.Combine (appBase, "Web.config"), + r.MapPath ("Web.config", "/NunitWeb/", false), "test8"); + Assert.AreEqual (Path.Combine (appBase, "Web.config"), + r.MapPath ("Web.config", "~", false), "test10"); + Assert.AreEqual (Path.Combine (appBase, "DIR" + Path.DirectorySeparatorChar + "Web.config"), + r.MapPath ("Web.config", "~/DIR", false), "test11"); } } -- 2.11.4.GIT