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
=== modified file 'NEWS'
--- NEWS 2009-11-26 01:42:06 +0000
+++ NEWS 2009-11-26 04:15:20 +0000
@@ -54,6 +54,10 @@
54Improvements54Improvements
55************55************
5656
57* ``bzrlib.urlutils.local_path_from_url`` now accepts
58 'file://localhost/' as well as 'file:///' URLs on POSIX. (Michael
59 Hudson)
60
57Documentation61Documentation
58*************62*************
5963
6064
=== modified file 'bzrlib/tests/test_urlutils.py'
--- bzrlib/tests/test_urlutils.py 2009-04-04 01:45:09 +0000
+++ bzrlib/tests/test_urlutils.py 2009-11-26 04:15:20 +0000
@@ -17,7 +17,6 @@
17"""Tests for the urlutils wrapper."""17"""Tests for the urlutils wrapper."""
1818
19import os19import os
20import re
21import sys20import sys
2221
23from bzrlib import osutils, urlutils, win32utils22from bzrlib import osutils, urlutils, win32utils
@@ -300,8 +299,13 @@
300 from_url('file:///path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))299 from_url('file:///path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
301 self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',300 self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
302 from_url('file:///path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))301 from_url('file:///path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
302 self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
303 from_url('file://localhost/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
303304
304 self.assertRaises(InvalidURL, from_url, '/path/to/foo')305 self.assertRaises(InvalidURL, from_url, '/path/to/foo')
306 self.assertRaises(
307 InvalidURL, from_url,
308 'file://remotehost/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s')
305309
306 def test_win32_local_path_to_url(self):310 def test_win32_local_path_to_url(self):
307 to_url = urlutils._win32_local_path_to_url311 to_url = urlutils._win32_local_path_to_url
308312
=== modified file 'bzrlib/urlutils.py'
--- bzrlib/urlutils.py 2009-07-16 07:10:45 +0000
+++ bzrlib/urlutils.py 2009-11-26 04:15:20 +0000
@@ -217,10 +217,16 @@
217# jam 20060502 Sorted to 'l' because the final target is 'local_path_from_url'217# jam 20060502 Sorted to 'l' because the final target is 'local_path_from_url'
218def _posix_local_path_from_url(url):218def _posix_local_path_from_url(url):
219 """Convert a url like file:///path/to/foo into /path/to/foo"""219 """Convert a url like file:///path/to/foo into /path/to/foo"""
220 if not url.startswith('file:///'):220 file_localhost_prefix = 'file://localhost/'
221 raise errors.InvalidURL(url, 'local urls must start with file:///')221 if url.startswith(file_localhost_prefix):
222 path = url[len(file_localhost_prefix) - 1:]
223 elif not url.startswith('file:///'):
224 raise errors.InvalidURL(
225 url, 'local urls must start with file:/// or file://localhost/')
226 else:
227 path = url[len('file://'):]
222 # We only strip off 2 slashes228 # We only strip off 2 slashes
223 return unescape(url[len('file://'):])229 return unescape(path)
224230
225231
226def _posix_local_path_to_url(path):232def _posix_local_path_to_url(path):