Author: igorz
Date: 2006-12-05 12:17:36 -0500 (Tue, 05 Dec 2006)
New Revision: 69056
Modified:
trunk/mcs/class/System.Web/System.Web/ChangeLog
trunk/mcs/class/System.Web/System.Web/VirtualPathUtility.cs
trunk/mcs/class/System.Web/Test/System.Web/ChangeLog
trunk/mcs/class/System.Web/Test/System.Web/VirtualPathUtilityTest.cs
Log:
2006-12-05 Igor Zelmanovich <[EMAIL PROTECTED]>
* VirtualPathUtility.cs: fixed: ToAbsolute() method.
Modified: trunk/mcs/class/System.Web/System.Web/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web/ChangeLog 2006-12-05 16:57:07 UTC
(rev 69055)
+++ trunk/mcs/class/System.Web/System.Web/ChangeLog 2006-12-05 17:17:36 UTC
(rev 69056)
@@ -1,3 +1,7 @@
+2006-12-05 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * VirtualPathUtility.cs: fixed: ToAbsolute() method.
+
2006-12-05 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* HttpRequest.cs: call MapPath on the HttpWorkerRequest so that if
Modified: trunk/mcs/class/System.Web/System.Web/VirtualPathUtility.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/VirtualPathUtility.cs 2006-12-05
16:57:07 UTC (rev 69055)
+++ trunk/mcs/class/System.Web/System.Web/VirtualPathUtility.cs 2006-12-05
17:17:36 UTC (rev 69056)
@@ -155,6 +155,10 @@
return ToAbsolute (virtualPath,apppath);
}
+ // If virtualPath is:
+ // Absolute, the ToAbsolute method returns the virtual path
with no changes.
+ // Application relative, the ToAbsolute method adds
applicationPath to the beginning of the virtual path.
+ // Not rooted, the ToAbsolute method raises an
ArgumentOutOfRangeException exception.
public static string ToAbsolute (string virtualPath, string
applicationPath)
{
if (applicationPath == null || applicationPath == "")
@@ -163,14 +167,17 @@
if (virtualPath == null || virtualPath == "")
throw new ArgumentNullException ("virtualPath");
- if (virtualPath.StartsWith (".."))
+ if (virtualPath.Length > 1 && virtualPath [0] == '~' &&
virtualPath [1] == '/') {
+ if (applicationPath [0] != '/')
+ throw new ArgumentException ("appPath
is not rooted", "applicationPath");
+ return UrlUtils.RemoveDoubleSlashes
((applicationPath + virtualPath.Substring (1)).Replace ('\\', '/'));
+ }
+
+ if (virtualPath [0] != '/')
throw new ArgumentException (String.Format
("Relative path not allowed: '{0}'", virtualPath));
- if (applicationPath [0] != '/')
- throw new ArgumentOutOfRangeException ("appPath
is not rooted", "applicationPath");
+ return UrlUtils.RemoveDoubleSlashes
(virtualPath.Replace ('\\', '/'));
- return UrlUtils.Combine (applicationPath, virtualPath);
-
}
public static string ToAppRelative (string virtualPath)
Modified: trunk/mcs/class/System.Web/Test/System.Web/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web/ChangeLog 2006-12-05
16:57:07 UTC (rev 69055)
+++ trunk/mcs/class/System.Web/Test/System.Web/ChangeLog 2006-12-05
17:17:36 UTC (rev 69056)
@@ -1,3 +1,7 @@
+2006-12-05 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * VirtualPathUtilityTest.cs: new tests added.
+
2006-11-29 Igor Zelmanovich <[EMAIL PROTECTED]>
* StaticSiteMapProviderTest.cs: fixed NunitWeb tests.
Modified: trunk/mcs/class/System.Web/Test/System.Web/VirtualPathUtilityTest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web/VirtualPathUtilityTest.cs
2006-12-05 16:57:07 UTC (rev 69055)
+++ trunk/mcs/class/System.Web/Test/System.Web/VirtualPathUtilityTest.cs
2006-12-05 17:17:36 UTC (rev 69056)
@@ -437,8 +437,50 @@
{
Assert.AreEqual ("/", VPU.ToAbsolute ("/"));
}
+
+ [Test]
+ public void ToAbsolute8 ()
+ {
+ Assert.AreEqual ("/", VPU.ToAbsolute ("/", "/ROOT"));
+ Assert.AreEqual ("/blah/blah/", VPU.ToAbsolute
("/blah//blah//", "/ROOT"));
+ Assert.AreEqual ("/blah/blah/", VPU.ToAbsolute
("/blah\\blah/", "/ROOT"));
+ }
+
+ [Test]
+ public void ToAbsolute9 ()
+ {
+ Assert.AreEqual ("/ROOT/", VPU.ToAbsolute ("~/",
"/ROOT"));
+ Assert.AreEqual ("/ROOT/blah", VPU.ToAbsolute
("~/blah", "/ROOT/"));
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ToAbsolute10 ()
+ {
+ VPU.ToAbsolute ("../blah", "/ROOT");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ToAbsolute11 ()
+ {
+ VPU.ToAbsolute ("blah", "/ROOT");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ToAbsolute12 ()
+ {
+ VPU.ToAbsolute ("~/blah", "ROOT");
+ }
+
+ [Test]
+ public void ToAbsolute13 ()
+ {
+ Assert.AreEqual ("/blah", VPU.ToAbsolute ("/blah",
"ROOT"));
+ }
}
}
-#endif
-
+#endif
+
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches