Rev 2958: MemoryTransport._abspath: fix handling of '..' and other strangeness in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sat Nov 3 03:26:29 GMT 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2958
revision-id: pqm at pqm.ubuntu.com-20071103032627-fvl5prorhuns0t4o
parent: pqm at pqm.ubuntu.com-20071103023739-e0wzok4qpvzq66sa
parent: mbp at sourcefrog.net-20071103010733-0a65i4zksk38or4u
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2007-11-03 03:26:27 +0000
message:
MemoryTransport._abspath: fix handling of '..' and other strangeness
modified:
bzrlib/transport/memory.py memory.py-20051016101338-cd008dbdf69f04fc
------------------------------------------------------------
revno: 2940.3.1
merged: mbp at sourcefrog.net-20071103010733-0a65i4zksk38or4u
parent: pqm at pqm.ubuntu.com-20071025022746-ftudwmzir8v2lccc
committer: mbp at sourcefrog.net
branch nick: memorytransport
timestamp: Fri 2007-11-02 21:07:33 -0400
message:
MemoryTransport._abspath: fix handling of '..' and other strangeness
=== modified file 'bzrlib/transport/memory.py'
--- a/bzrlib/transport/memory.py 2007-10-04 22:00:07 +0000
+++ b/bzrlib/transport/memory.py 2007-11-03 01:07:33 +0000
@@ -261,21 +261,24 @@
def _abspath(self, relpath):
"""Generate an internal absolute path."""
relpath = urlutils.unescape(relpath)
- if relpath.find('..') != -1:
- raise AssertionError('relpath contains ..')
if relpath == '':
return '/'
if relpath[0] == '/':
return relpath
- if relpath == '.':
- if (self._cwd == '/'):
- return self._cwd
- return self._cwd[:-1]
- if relpath.endswith('/'):
- relpath = relpath[:-1]
- if relpath.startswith('./'):
- relpath = relpath[2:]
- return self._cwd + relpath
+ cwd_parts = self._cwd.split('/')
+ rel_parts = relpath.split('/')
+ r = []
+ for i in cwd_parts + rel_parts:
+ if i == '..':
+ if not r:
+ raise ValueError("illegal relpath %r under %r"
+ % relpath, self._cwd)
+ r = r[:-1]
+ elif i == '.' or i == '':
+ pass
+ else:
+ r.append(i)
+ return '/' + '/'.join(r)
class _MemoryLock(object):
More information about the bazaar-commits
mailing list