url: special case bundle URL parsing to preserve backwards compatibility
authorBrodie Rao <brodie@bitheap.org>
Wed, 30 Mar 2011 20:00:24 -0700
changeset 13816 2540f8087e02
parent 13815 d066d8d652c8
child 13817 7f18bab2c0b0
url: special case bundle URL parsing to preserve backwards compatibility This allows bundle://../foo to continue to refer to the relative path ../foo (bundle URLs do not take host names).
mercurial/url.py
--- a/mercurial/url.py	Wed Mar 30 20:00:23 2011 -0700
+++ b/mercurial/url.py	Wed Mar 30 20:00:24 2011 -0700
@@ -29,6 +29,9 @@
 
     See http://www.ietf.org/rfc/rfc2396.txt for more information.
 
+    Note that for backward compatibility reasons, bundle URLs do not
+    take host names. That means 'bundle://../' has a path of '../'.
+
     Examples:
 
     >>> url('http://www.ietf.org/rfc/rfc2396.txt')
@@ -39,6 +42,8 @@
     <url scheme: 'file', path: '/home/joe/repo'>
     >>> url('bundle:foo')
     <url scheme: 'bundle', path: 'foo'>
+    >>> url('bundle://../foo')
+    <url scheme: 'bundle', path: '../foo'>
     >>> url('c:\\\\foo\\\\bar')
     <url path: 'c:\\\\foo\\\\bar'>
 
@@ -71,6 +76,16 @@
             self.path = path
             return
 
+        # For compatibility reasons, we can't handle bundle paths as
+        # normal URLS
+        if path.startswith('bundle:'):
+            self.scheme = 'bundle'
+            path = path[7:]
+            if path.startswith('//'):
+                path = path[2:]
+            self.path = path
+            return
+
         if not path.startswith('/') and ':' in path:
             parts = path.split(':', 1)
             if parts[0]:
@@ -159,11 +174,15 @@
         'http://localhost:80/'
         >>> str(url('bundle:foo'))
         'bundle:foo'
+        >>> str(url('bundle://../foo'))
+        'bundle:../foo'
         >>> str(url('path'))
         'path'
         """
         if self._localpath:
             s = self.path
+            if self.scheme == 'bundle':
+                s = 'bundle:' + s
             if self.fragment:
                 s += '#' + self.fragment
             return s