[Python-checkins] cpython (merge 3.4 -> default): Issue #9850: Fixed macpath.join() for empty first component. Patch by

serhiy.storchaka python-checkins at python.org
Sat Sep 27 17:58:39 CEST 2014


https://hg.python.org/cpython/rev/e29866cb6b98
changeset:   92597:e29866cb6b98
parent:      92594:d43d4d4ebf2c
parent:      92596:54987723de99
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sat Sep 27 18:55:15 2014 +0300
summary:
  Issue #9850: Fixed macpath.join() for empty first component.  Patch by
Oleg Oshmyan.

files:
  Lib/macpath.py           |   2 +-
  Lib/test/test_macpath.py |  24 ++++++++++++++++++++++++
  Misc/NEWS                |   3 +++
  3 files changed, 28 insertions(+), 1 deletions(-)


diff --git a/Lib/macpath.py b/Lib/macpath.py
--- a/Lib/macpath.py
+++ b/Lib/macpath.py
@@ -53,7 +53,7 @@
     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
--- a/Lib/test/test_macpath.py
+++ b/Lib/test/test_macpath.py
@@ -49,16 +49,40 @@
     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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -145,6 +145,9 @@
 Library
 -------
 
+- Issue #9850: Fixed macpath.join() for empty first component.  Patch by
+  Oleg Oshmyan.
+
 - Issue #5309: distutils' build and build_ext commands now accept a ``-j``
   option to enable parallel building of extension modules.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list