From ca534ab4957f3ed081133f2174543d8a560a4051 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 27 Sep 2014 18:53:23 +0300 Subject: [PATCH] Issue #9850: Fixed macpath.join() for empty first component. Patch by Oleg Oshmyan. --- Lib/macpath.py | 2 +- Lib/test/test_macpath.py | 24 ++++++++++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Lib/macpath.py b/Lib/macpath.py index d34f9e944cc..5ca00977c6d 100644 --- a/Lib/macpath.py +++ b/Lib/macpath.py @@ -53,7 +53,7 @@ def join(s, *p): colon = _get_colon(s) path = s for t in p: - if (not s) or isabs(t): + if (not path) or isabs(t): path = t continue if t[:1] == colon: diff --git a/Lib/test/test_macpath.py b/Lib/test/test_macpath.py index ae4e5640fa9..22f84919bb9 100644 --- a/Lib/test/test_macpath.py +++ b/Lib/test/test_macpath.py @@ -49,16 +49,40 @@ class MacPathTestCase(unittest.TestCase): 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:') self.assertEqual(join(b'a', b'b'), b':a:b') + self.assertEqual(join(b':a', b'b'), b':a:b') + self.assertEqual(join(b':a:', b'b'), b':a:b') + self.assertEqual(join(b':a::', b'b'), b':a::b') + self.assertEqual(join(b':a', b'::b'), b':a::b') + self.assertEqual(join(b'a', b':'), b':a:') + self.assertEqual(join(b'a:', b':'), b'a:') + self.assertEqual(join(b'a', b''), b':a:') + self.assertEqual(join(b'a:', b''), b'a:') + self.assertEqual(join(b'', b''), b'') self.assertEqual(join(b'', b'a:b'), b'a:b') + self.assertEqual(join(b'', b'a', b'b'), b':a:b') self.assertEqual(join(b'a:b', b'c'), b'a:b:c') self.assertEqual(join(b'a:b', b':c'), b'a:b:c') self.assertEqual(join(b'a', b':b', b':c'), b':a:b:c') + self.assertEqual(join(b'a', b'b:'), b'b:') + self.assertEqual(join(b'a:', b'b:'), b'b:') def test_splitext(self): splitext = macpath.splitext diff --git a/Misc/NEWS b/Misc/NEWS index 2f3d9d127ce..0b8ba0c1054 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -27,6 +27,9 @@ Core and Builtins Library ------- +- Issue #9850: Fixed macpath.join() for empty first component. Patch by + Oleg Oshmyan. + - Issue #22427: TemporaryDirectory no longer attempts to clean up twice when used in the with statement in generator.