summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-27 15:53:01 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-27 15:53:01 (GMT)
commite430073fe739cbba200742ed9e884d4a067bd0d0 (patch)
tree1ed58d61a9c87c177dea363041059202ce4e3a62
parent6e7c14013a8e6564bb67edc92b1264e2fc4c9af5 (diff)
downloadcpython-e430073fe739cbba200742ed9e884d4a067bd0d0.zip
cpython-e430073fe739cbba200742ed9e884d4a067bd0d0.tar.gz
cpython-e430073fe739cbba200742ed9e884d4a067bd0d0.tar.bz2
Issue #9850: Fixed macpath.join() for empty first component. Patch by
Oleg Oshmyan.
-rw-r--r--Lib/macpath.py2
-rw-r--r--Lib/test/test_macpath.py20
-rw-r--r--Misc/NEWS3
3 files changed, 24 insertions, 1 deletions
diff --git a/Lib/macpath.py b/Lib/macpath.py
index cd4cb85..c31bdaa 100644
--- a/Lib/macpath.py
+++ b/Lib/macpath.py
@@ -42,7 +42,7 @@ def isabs(s):
def join(s, *p):
path = s
for t in p:
- if (not s) or isabs(t):
+ if (not path) or isabs(t):
path = t
continue
if t[:1] == ':':
diff --git a/Lib/test/test_macpath.py b/Lib/test/test_macpath.py
index 2c86c53..96ad61f 100644
--- a/Lib/test/test_macpath.py
+++ b/Lib/test/test_macpath.py
@@ -29,6 +29,26 @@ class MacPathTestCase(unittest.TestCase):
self.assertEqual(split(":conky:mountpoint:"),
(':conky:mountpoint', ''))
+ def test_join(self):
+ join = macpath.join
+ self.assertEqual(join('a', 'b'), ':a:b')
+ self.assertEqual(join(':a', 'b'), ':a:b')
+ self.assertEqual(join(':a:', 'b'), ':a:b')
+ self.assertEqual(join(':a::', 'b'), ':a::b')
+ self.assertEqual(join(':a', '::b'), ':a::b')
+ self.assertEqual(join('a', ':'), ':a:')
+ self.assertEqual(join('a:', ':'), 'a:')
+ self.assertEqual(join('a', ''), ':a:')
+ self.assertEqual(join('a:', ''), 'a:')
+ self.assertEqual(join('', ''), '')
+ self.assertEqual(join('', 'a:b'), 'a:b')
+ self.assertEqual(join('', 'a', 'b'), ':a:b')
+ self.assertEqual(join('a:b', 'c'), 'a:b:c')
+ self.assertEqual(join('a:b', ':c'), 'a:b:c')
+ self.assertEqual(join('a', ':b', ':c'), ':a:b:c')
+ self.assertEqual(join('a', 'b:'), 'b:')
+ self.assertEqual(join('a:', 'b:'), 'b:')
+
def test_splitext(self):
splitext = macpath.splitext
self.assertEqual(splitext(":foo.ext"), (':foo', '.ext'))
diff --git a/Misc/NEWS b/Misc/NEWS
index 02e9c4c..2ad73fd 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,9 @@ Core and Builtins
Library
-------
+- Issue #9850: Fixed macpath.join() for empty first component. Patch by
+ Oleg Oshmyan.
+
- Issue #20912: Now directories added to ZIP file have correct Unix and MS-DOS
directory attributes.