[[[

Canonicalise URIs which have an empty hostname part correctly.
This fixes the crash described in #2116 ('svn log file:///'
results in a failed assertion).

* subversion/libsvn_subr/path.c
  (svn_path_canonicalize): We used to strip the trailing slash
   of URIs with no hostname, e.g. http:// got canonicalised to http:/
   Don't do that!

* subversion/tests/libsvn_subr/path-test.c
  (test_canonicalize): Add some test cases for the above.
]]]

Index: subversion/libsvn_subr/path.c
===================================================================
--- subversion/libsvn_subr/path.c	(revision 31628)
+++ subversion/libsvn_subr/path.c	(working copy)
@@ -1309,9 +1309,17 @@ svn_path_canonicalize(const char *path, apr_pool_t
         src++;
     }
 
-  /* Remove the trailing slash. */
-  if ((canon_segments > 0 || uri) && *(dst - 1) == '/')
-    dst--;
+  /* Remove the trailing slash if necessary. */
+  if (*(dst - 1) == '/')
+    {
+      /* If we had any path components, we always remove the trailing slash. */
+      if (canon_segments > 0)
+        dst --;
+      /* Otherwise, make sure to strip the third slash from URIs which
+       * have an empty hostname part, such as http:/// or file:/// */
+      else if (uri && strncmp(dst - 3, "//", 2) == 0)
+        dst--;
+    }
 
   *dst = '\0';
 
Index: subversion/tests/libsvn_subr/path-test.c
===================================================================
--- subversion/tests/libsvn_subr/path-test.c	(revision 31628)
+++ subversion/tests/libsvn_subr/path-test.c	(working copy)
@@ -736,6 +736,12 @@ test_canonicalize(const char **msg,
     { "http://hst",           "http://hst" },
     { "http://hst/foo/../bar","http://hst/foo/../bar" },
     { "http://hst/",          "http://hst" },
+    { "http:///",             "http://" },
+    { "https://",             "https://" },
+    { "file:///",             "file://" },
+    { "file://",              "file://" },
+    { "svn:///",              "svn://" },
+    { "svn+ssh:///",          "svn+ssh://" },
     { NULL, NULL }
   };
   int i;

