Rev 4778: (andrew) Handle unicode paths correctly in the smart server. (#458762) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Oct 30 00:00:39 GMT 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4778 [merge]
revision-id: pqm at pqm.ubuntu.com-20091030000037-8t6z4344pii34mb6
parent: pqm at pqm.ubuntu.com-20091029220043-u2qbo0ci5867xniz
parent: andrew.bennetts at canonical.com-20091029002707-b2pyhbf938zg4ses
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2009-10-30 00:00:37 +0000
message:
(andrew) Handle unicode paths correctly in the smart server. (#458762)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/smart/request.py request.py-20061108095550-gunadhxmzkdjfeek-1
bzrlib/smart/vfs.py vfs.py-20061108095550-gunadhxmzkdjfeek-2
bzrlib/tests/test_smart.py test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
doc/developers/network-protocol.txt networkprotocol.txt-20070903044232-woustorrjbmg5zol-1
=== modified file 'NEWS'
--- a/NEWS 2009-10-29 21:13:16 +0000
+++ b/NEWS 2009-10-30 00:00:37 +0000
@@ -42,6 +42,9 @@
* TreeTransform.adjust_path updates the limbo paths of descendants of adjusted
files. (Aaron Bentley)
+* Unicode paths are now handled correctly and consistently by the smart
+ server. (Andrew Bennetts, Michael Hudson, #458762)
+
Improvements
************
=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py 2009-10-22 06:53:08 +0000
+++ b/bzrlib/smart/request.py 2009-10-29 00:25:26 +0000
@@ -188,7 +188,7 @@
relpath = urlutils.joinpath('/', path)
if not relpath.startswith('/'):
raise ValueError(relpath)
- return '.' + relpath
+ return urlutils.escape('.' + relpath)
else:
raise errors.PathNotChild(client_path, self._root_client_path)
=== modified file 'bzrlib/smart/vfs.py'
--- a/bzrlib/smart/vfs.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/smart/vfs.py 2009-10-23 04:22:05 +0000
@@ -27,6 +27,7 @@
import os
from bzrlib import errors
+from bzrlib import urlutils
from bzrlib.smart import request
@@ -59,6 +60,14 @@
if not vfs_enabled():
raise errors.DisabledMethod(self.__class__.__name__)
+ def translate_client_path(self, relpath):
+ # VFS requests are made with escaped paths so the escaping done in
+ # SmartServerRequest.translate_client_path leads to double escaping.
+ # Remove it here -- the fact that the result is still escaped means
+ # that the str() will not fail on valid input.
+ x = request.SmartServerRequest.translate_client_path(self, relpath)
+ return str(urlutils.unescape(x))
+
class HasRequest(VfsRequest):
=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py 2009-09-24 05:31:23 +0000
+++ b/bzrlib/tests/test_smart.py 2009-10-29 00:16:50 +0000
@@ -43,6 +43,7 @@
import bzrlib.smart.bzrdir, bzrlib.smart.bzrdir as smart_dir
import bzrlib.smart.packrepository
import bzrlib.smart.repository
+import bzrlib.smart.vfs
from bzrlib.smart.request import (
FailedSmartServerResponse,
SmartServerRequest,
@@ -170,6 +171,18 @@
self.assertRaises(
errors.PathNotChild, request.translate_client_path, 'bar/')
self.assertEqual('./baz', request.translate_client_path('foo/baz'))
+ e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'.encode('utf-8')
+ self.assertEqual('./' + urlutils.escape(e_acute),
+ request.translate_client_path('foo/' + e_acute))
+
+ def test_translate_client_path_vfs(self):
+ """VfsRequests receive escaped paths rather than raw UTF-8."""
+ transport = self.get_transport()
+ request = smart.vfs.VfsRequest(transport, 'foo/')
+ e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'.encode('utf-8')
+ escaped = urlutils.escape('foo/' + e_acute)
+ self.assertEqual('./' + urlutils.escape(e_acute),
+ request.translate_client_path(escaped))
def test_transport_from_client_path(self):
transport = self.get_transport()
@@ -1690,6 +1703,19 @@
self.assertEqual(SmartServerResponse(('ok',)), response)
+class TestSmartServerVfsGet(tests.TestCaseWithMemoryTransport):
+
+ def test_unicode_path(self):
+ """VFS requests expect unicode paths to be escaped."""
+ filename = u'foo\N{INTERROBANG}'
+ filename_escaped = urlutils.escape(filename)
+ backing = self.get_transport()
+ request = smart.vfs.GetRequest(backing)
+ backing.put_bytes_non_atomic(filename_escaped, 'contents')
+ self.assertEqual(SmartServerResponse(('ok', ), 'contents'),
+ request.execute(filename_escaped))
+
+
class TestHandlers(tests.TestCase):
"""Tests for the request.request_handlers object."""
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2009-09-24 05:31:23 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2009-10-27 06:30:37 +0000
@@ -657,8 +657,10 @@
# wire-to-wire, using the whole stack, with a UTF-8 filename.
transport = memory.MemoryTransport('memory:///')
utf8_filename = u'testfile\N{INTERROBANG}'.encode('utf-8')
+ # VFS requests use filenames, not raw UTF-8.
+ hpss_path = urlutils.escape(utf8_filename)
transport.put_bytes(utf8_filename, 'contents\nof\nfile\n')
- to_server = StringIO('get\001' + utf8_filename + '\n')
+ to_server = StringIO('get\001' + hpss_path + '\n')
from_server = StringIO()
server = medium.SmartServerPipeStreamMedium(
to_server, from_server, transport)
=== modified file 'doc/developers/network-protocol.txt'
--- a/doc/developers/network-protocol.txt 2009-09-17 03:21:14 +0000
+++ b/doc/developers/network-protocol.txt 2009-10-29 00:19:57 +0000
@@ -436,6 +436,9 @@
using `bzrlib.transport.pathfilter` and `os.path.expanduser`, taking care
to respect the virtual root.
+Paths in request arguments are UTF-8 encoded, except for the legacy VFS
+requests which expect escaped (`bzrlib.urlutils.escape`) paths.
+
Requests
========
More information about the bazaar-commits
mailing list