diff mercurial/util.py @ 9996:2770d03ae49f stable

handle file URIs correctly, according to RFC 2396 (issue1153) The new code aims to implement the RFC correctly for file URIs. Previously they were handled incorrectly in several ways, which could cause problem on Windows in particular.
author Sune Foldager <cryo@cyanite.org>
date Thu, 03 Dec 2009 11:06:55 +0100
parents 092bcf431562
children 29e3c4a7699b 25e572394f5c
line wrap: on
line diff
--- a/mercurial/util.py	Thu Dec 03 11:06:44 2009 +0100
+++ b/mercurial/util.py	Thu Dec 03 11:06:55 2009 +0100
@@ -1197,7 +1197,19 @@
     if path.startswith(sc):
         path = path[len(sc):]
         if path.startswith('//'):
-            path = path[2:]
+            if scheme == 'file':
+                i = path.find('/', 2)
+                if i == -1:
+                    return ''
+                # On Windows, absolute paths are rooted at the current drive
+                # root. On POSIX they are rooted at the file system root.
+                if os.name == 'nt':
+                    droot = os.path.splitdrive(os.getcwd())[0] + '/'
+                    path = os.path.join(droot, path[i+1:])
+                else:
+                    path = path[i:]
+            else:
+                path = path[2:]
     return path
 
 def uirepr(s):