Переглянути джерело

2007-03-15 Igor Zelmanovich <[email protected]>

	* HttpRequest.cs: fixed MapPath () method.


svn path=/trunk/mcs/; revision=74403
Igor Zelmanovich 19 роки тому
батько
коміт
696773bd62

+ 2 - 0
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);
 		}
 

+ 4 - 0
mcs/class/System.Web/System.Web/ChangeLog

@@ -1,3 +1,7 @@
+2007-03-15 Igor Zelmanovich <[email protected]>
+
+	* HttpRequest.cs: fixed MapPath () method.
+
 2007-03-15 Igor Zelmanovich <[email protected]>
 
 	* VirtualPathUtility.cs: fixed ToAbsolute() method.

+ 14 - 3
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)

+ 8 - 10
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");
 		}
 	}