diff --git a/Lib/shlex.py b/Lib/shlex.py index f4c4ad8e484..595ea890433 100644 --- a/Lib/shlex.py +++ b/Lib/shlex.py @@ -316,7 +316,11 @@ def split(s, comments=False, posix=True): lex.whitespace_split = True if not comments: lex.commenters = '' - return list(lex) + + if isinstance(s, bytes): + return [i.encode("ascii") for i in lex] + else: + return list(lex) def join(split_command): diff --git a/Lib/test/test_shlex.py b/Lib/test/test_shlex.py index ae9a6033e15..517d10aa421 100644 --- a/Lib/test/test_shlex.py +++ b/Lib/test/test_shlex.py @@ -171,9 +171,9 @@ class ShlexTest(unittest.TestCase): """Test data splitting with posix parser""" self.splitTest(self.posix_data, comments=True) - def splitBytesTest(self): + def testSplitBytes(self): """Test byte objects splitting""" - self.assertEqual(shlex.split(b"split words"), [b"hello", b"world"]) + self.assertEqual(shlex.split(b"split words"), [b"split", b"words"]) def testCompat(self): """Test compatibility interface"""