From: Hynek Schlawack Date: Tue, 17 Jul 2012 11:10:15 +0000 (+0200) Subject: #15377: Make posixpath.join() more strict when checking for str/bytes mix X-Git-Tag: v3.3.0b2~177 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1815191f1722546f6af2b5207df4efaa50be38fd;p=python #15377: Make posixpath.join() more strict when checking for str/bytes mix Based on a patch by Nick Coghlan. --- 1815191f1722546f6af2b5207df4efaa50be38fd diff --cc Lib/posixpath.py index ab2aefface,7a4daa8be9..39b16a87c7 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@@ -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 diff --cc Lib/test/test_posixpath.py index e89f22e6fc,89c4f9e99d..060fdc3fd4 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@@ -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