]> granicus.if.org Git - python/commitdiff
#15377: Make posixpath.join() more strict when checking for str/bytes mix
authorHynek Schlawack <hs@ox.cx>
Tue, 17 Jul 2012 11:10:15 +0000 (13:10 +0200)
committerHynek Schlawack <hs@ox.cx>
Tue, 17 Jul 2012 11:10:15 +0000 (13:10 +0200)
Based on a patch by Nick Coghlan.

1  2 
Lib/posixpath.py
Lib/test/test_posixpath.py

index ab2aefface39e55962d18f1036c23537f8be4896,7a4daa8be946109852675081b1fb072acadbfb2f..39b16a87c7803ddb4473f423290b4babf7ca506d
@@@ -83,12 -83,12 +83,13 @@@ def join(a, *p)
              else:
                  path += sep + b
      except TypeError:
-         strs = [isinstance(s, str) for s in (a, ) + p]
-         if any(strs) and not all(strs):
+         valid_types = all(isinstance(s, (str, bytes, bytearray))
+                           for s in (a, ) + p)
+         if valid_types:
+             # Must have a mixture of text and binary data
 -            raise TypeError("Can't mix strings and bytes in path components.")
 +            raise TypeError("Can't mix strings and bytes in path "
 +                            "components.") from None
-         else:
-             raise
+         raise
      return path
  
  
index e89f22e6fc6cf5afa13b79b7d94e6ed3bba11043,89c4f9e99da123a1cdbf7b9e01b8660cc74dc964..060fdc3fd40f860dc587c60727769b6d634fc56e
@@@ -1,10 -1,11 +1,11 @@@
 -import unittest
 -from test import support, test_genericpath
 -
+ import itertools
 -import posixpath
  import os
 +import posixpath
  import sys
 +import unittest
 +import warnings
  from posixpath import realpath, abspath, dirname, basename
 +from test import support, test_genericpath
  
  try:
      import posix