2006-01-31 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 31 Jan 2006 22:00:13 +0000 (22:00 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 31 Jan 2006 22:00:13 +0000 (22:00 -0000)
* UrlUtils.cs: more than one consecutive slash are turned into one.

svn path=/trunk/mcs/; revision=56368

mcs/class/System.Web/System.Web.Util/ChangeLog
mcs/class/System.Web/System.Web.Util/UrlUtils.cs

index db4fbc07cca747262fdc5486befddbe24f63a48d..69e966cf49538b52d6363bc4586a0f2233e47d68 100644 (file)
@@ -1,3 +1,7 @@
+2006-01-31 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * UrlUtils.cs: more than one consecutive slash are turned into one.
+
 2006-01-26  Chris Toshok  <toshok@ximian.com>
 
        * WebEncoding.cs: rework this so we cache the section, and so we
index 6e158a40c0b105f253ce9a87fedbc4f414c82f13..179158ec1ab20f1b8cf8f6c4fd2784b1cadbc4aa 100644 (file)
@@ -177,17 +177,41 @@ namespace System.Web.Util {
                {
                        url = url.Replace('\\','/');
                        int last = url.LastIndexOf ('/');
-                       if (last > 0)
+
+                       if (last > 0) {
+#if NET_2_0
+                               return RemoveDoubleSlashes (url.Substring (0, last));
+#else
                                return url.Substring (0, last);
+#endif
+                       }
+
                        return "/";
                }
 
+#if NET_2_0
+               internal static string RemoveDoubleSlashes (string input)
+               {
+                       // MS VirtualPathUtility removes duplicate '/'
+                       string str = input;
+                       string x;
+                       while ((x = str.Replace ("//", "/")) != str) {
+                               str = x;
+                       }
+
+                       return str;
+               }
+#endif
+
                internal static string GetFile (string url)
                {
                        url = url.Replace('\\','/');
                        int last = url.LastIndexOf ('/');
-                       if (last >= 0)
+                       if (last >= 0) {
+                               if (url.Length == 1) // Empty file name instead of ArgumentOutOfRange
+                                       return "";
                                return url.Substring (last+1);
+                       }
 
                        throw new Exception (String.Format ("GetFile: `{0}' does not contain a /", url));
                }