diff options
author | gcode@loowis.durge.org <gcode@loowis.durge.org@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-12-22 23:08:15 +0000 |
---|---|---|
committer | gcode@loowis.durge.org <gcode@loowis.durge.org@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-12-22 23:08:15 +0000 |
commit | 4a5b5409eefc21e1ebfae86371774e1ebfb112fc (patch) | |
tree | 8d6a9a96763afef1413af358872e909993b13299 | |
parent | 43854af50ea1e6860f4dca65438f94aec07ff29e (diff) | |
download | pyfilesystem-git-4a5b5409eefc21e1ebfae86371774e1ebfb112fc.tar.gz |
Made normpath('/.') and normpath('/..') behave more consistently
-rw-r--r-- | fs/path.py | 5 | ||||
-rw-r--r-- | fs/tests/test_path.py | 3 |
2 files changed, 6 insertions, 2 deletions
@@ -46,7 +46,8 @@ def normpath(path): if not _requires_normalization(path): return path.rstrip('/') - components = [''] if path.startswith('/') else [] + prefix = u'/' if path.startswith('/') else u'' + components = [] append = components.append special = ('..', '.', '').__contains__ try: @@ -61,7 +62,7 @@ def normpath(path): # causing a circular import. from fs.errors import BackReferenceError raise BackReferenceError('Too many backrefs in \'%s\'' % path) - return u'/'.join(components) + return prefix + u'/'.join(components) if os.sep != '/': diff --git a/fs/tests/test_path.py b/fs/tests/test_path.py index b4e062f..dc023a3 100644 --- a/fs/tests/test_path.py +++ b/fs/tests/test_path.py @@ -18,6 +18,7 @@ class TestPathFunctions(unittest.TestCase): (".", ""), ("./", ""), ("", ""), + ("/.", "/"), ("/a/b/c", "/a/b/c"), ("a/b/c", "a/b/c"), ("a/b/../c/", "a/c"), @@ -50,7 +51,9 @@ class TestPathFunctions(unittest.TestCase): result = testpaths[-1] self.assertEqual(pathjoin(*paths), result) + self.assertRaises(ValueError, pathjoin, "..") self.assertRaises(ValueError, pathjoin, "../") + self.assertRaises(ValueError, pathjoin, "/..") self.assertRaises(ValueError, pathjoin, "./../") self.assertRaises(ValueError, pathjoin, "a/b", "../../..") self.assertRaises(ValueError, pathjoin, "a/b/../../../d") |