Fix handling of empty quoted string in shlex

This commit is contained in:
Kovid Goyal
2025-04-26 08:55:32 +05:30
parent e942bc817b
commit 2093fb1310
2 changed files with 15 additions and 8 deletions

View File

@@ -683,6 +683,12 @@ class TestDataTypes(BaseTest):
tuple(shlex_split(bad))
for q, expected in {
'a""': ((0, 'a'),),
'a""b': ((0, 'ab'),),
'-1 "" 2': ((0, '-1'), (3, ''), (6, '2')),
"-1 '' 2": ((0, '-1'), (3, ''), (6, '2')),
'a ""': ((0, 'a'), (2, '')),
'""': ((0, ''),),
'"ab"': ((0, 'ab'),),
r'x "ab"y \m': ((0, 'x'), (2, 'aby'), (8, 'm')),
r'''x'y"\z'1''': ((0, 'xy"\\z1'),),
@@ -694,11 +700,11 @@ class TestDataTypes(BaseTest):
'😀 a': ((0, '😀'), (2, 'a')),
' \t😀a': ((2, '😀a'),),
}.items():
actual = tuple(shlex_split_with_positions(q))
self.ae(expected, actual, f'Failed for text: {q!r}')
ex = tuple(x[1] for x in expected)
actual = tuple(shlex_split(q))
self.ae(ex, actual, f'Failed for text: {q!r}')
actual = tuple(shlex_split_with_positions(q))
self.ae(expected, actual, f'Failed for text: {q!r}')
for q, expected in {
"$'ab'": ((0, 'ab'),),