Merge lp:~mwhudson/bzr/file-localhost-paths-are-ok into lp:bzr

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: not available
Proposed branch: lp:~mwhudson/bzr/file-localhost-paths-are-ok
Merge into: lp:bzr
Diff against target: 64 lines (+18/-4)
3 files modified
NEWS (+4/-0)
bzrlib/tests/test_urlutils.py (+5/-1)
bzrlib/urlutils.py (+9/-3)
To merge this branch: bzr merge lp:~mwhudson/bzr/file-localhost-paths-are-ok
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+15263@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

bzrlib.urlutils.local_path_from_url doesn't accept file://localhost/ URLs and this (together with Launchpad only accepting them for equally daft reasons) finally annoyed me enough to submit this patch.

I'll try to fix Launchpad too :-)

Revision history for this message
Robert Collins (lifeless) wrote :

doit

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-11-26 01:42:06 +0000
3+++ NEWS 2009-11-26 04:15:20 +0000
4@@ -54,6 +54,10 @@
5 Improvements
6 ************
7
8+* ``bzrlib.urlutils.local_path_from_url`` now accepts
9+ 'file://localhost/' as well as 'file:///' URLs on POSIX. (Michael
10+ Hudson)
11+
12 Documentation
13 *************
14
15
16=== modified file 'bzrlib/tests/test_urlutils.py'
17--- bzrlib/tests/test_urlutils.py 2009-04-04 01:45:09 +0000
18+++ bzrlib/tests/test_urlutils.py 2009-11-26 04:15:20 +0000
19@@ -17,7 +17,6 @@
20 """Tests for the urlutils wrapper."""
21
22 import os
23-import re
24 import sys
25
26 from bzrlib import osutils, urlutils, win32utils
27@@ -300,8 +299,13 @@
28 from_url('file:///path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
29 self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
30 from_url('file:///path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
31+ self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
32+ from_url('file://localhost/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
33
34 self.assertRaises(InvalidURL, from_url, '/path/to/foo')
35+ self.assertRaises(
36+ InvalidURL, from_url,
37+ 'file://remotehost/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s')
38
39 def test_win32_local_path_to_url(self):
40 to_url = urlutils._win32_local_path_to_url
41
42=== modified file 'bzrlib/urlutils.py'
43--- bzrlib/urlutils.py 2009-07-16 07:10:45 +0000
44+++ bzrlib/urlutils.py 2009-11-26 04:15:20 +0000
45@@ -217,10 +217,16 @@
46 # jam 20060502 Sorted to 'l' because the final target is 'local_path_from_url'
47 def _posix_local_path_from_url(url):
48 """Convert a url like file:///path/to/foo into /path/to/foo"""
49- if not url.startswith('file:///'):
50- raise errors.InvalidURL(url, 'local urls must start with file:///')
51+ file_localhost_prefix = 'file://localhost/'
52+ if url.startswith(file_localhost_prefix):
53+ path = url[len(file_localhost_prefix) - 1:]
54+ elif not url.startswith('file:///'):
55+ raise errors.InvalidURL(
56+ url, 'local urls must start with file:/// or file://localhost/')
57+ else:
58+ path = url[len('file://'):]
59 # We only strip off 2 slashes
60- return unescape(url[len('file://'):])
61+ return unescape(path)
62
63
64 def _posix_local_path_to_url(path):