Permalink
Browse files

Bug fix: ignore trailing IFS whitespace chars as well.

Modified spec tests and unit tests to cover this case.

Addresses issue #61.  Alpine invokves 'scanelf', which apparently
outputs trailing spaces that tickled this bug.
  • Loading branch information...
Andy Chu
Andy Chu committed Jan 11, 2018
1 parent e9e8bf4 commit 98d39650154b202df1b9877d98776463c91b688f
Showing with 19 additions and 6 deletions.
  1. +10 −3 core/builtin_test.py
  2. +5 −0 core/legacy.py
  3. +4 −3 spec/builtin-io.test.sh
View
@@ -21,16 +21,23 @@ def testEchoLexer(self):
def testAppendParts(self):
# allow_escape is True by default, but False when the user passes -r.
CASES = [
(['Aa', 'b', ' a b'], 'Aa b \\ a\\ b'),
(['Aa', 'b', ' a b'], 100, 'Aa b \\ a\\ b'),
(['a', 'b', 'c'], 3, 'a b c '),
]
for expected_parts, line in CASES:
for expected_parts, max_results, line in CASES:
sp = legacy.IfsSplitter(legacy.DEFAULT_IFS, '')
spans = sp.Split(line, True)
print('--- %r' % line)
for span in spans:
print(' %s %s' % span)
parts = []
builtin._AppendParts(line, spans, 100, False, parts)
builtin._AppendParts(line, spans, max_results, False, parts)
self.assertEqual(expected_parts, parts)
print('---')
if __name__ == '__main__':
unittest.main()
View
@@ -323,6 +323,11 @@ def Split(self, s, allow_escape):
if i == n:
return spans
# Ignore trailing IFS whitespace too. This is necessary for the case:
# IFS=':' ; read x y z <<< 'a : b : c :'. We don't want
while s[n-1] in self.ifs_whitespace:
n -= 1
state = ST_START
while i < n:
c = s[i]
View
@@ -227,11 +227,12 @@ echo -n ZZZ | { read x; echo $?; echo $x; }
### Read builtin with multiple variables
# NOTE: there are TABS below
read x y z <<EOF
A B C D E
A B C D E
FG
EOF
echo "$x/$y/$z"
# stdout: A/B/C D E
echo "[$x/$y/$z]"
# stdout: [A/B/C D E]
# BUG dash stdout: [A/B/C D E ]
# status: 0
### Read builtin with not enough variables

0 comments on commit 98d3965

Please sign in to comment.