-
Notifications
You must be signed in to change notification settings - Fork 443
Closed
Labels
Component: Bash CodeEverything regarding the bash codeEverything regarding the bash codePriority: CriticalBroken behavior in nearly all environments, e.g. wrong test results, internal bats errorBroken behavior in nearly all environments, e.g. wrong test results, internal bats errorStatus: ConfirmedThe reproducer worked as describedThe reproducer worked as describedType: Bug
Milestone
Description
This line is not a safe way to split arbitrary data into lines (as the suppressed SC2206 notes), as it relies on Bash's wordsplitting logic which also expands globs.
MCVE:
$ bats --version
Bats 1.1.0
$ ls
bats-bug.bats some-file
$ cat bats-bug.bats
#!/usr/bin/env bats
@test "bats bug" {
run printf 'foo\n*\nbar\n'
printf 'Output:\n%s\n\n' "$output"
echo "Lines:"
printf ' %s\n' "${lines[@]}"
[[ "${lines[1]}" == "*" ]]
}
$ bats bats-bug.bats
✗ bats bug
(in test file bats-bug.bats, line 7)
`printf ' %s\n' "${lines[@]}"' failed
Output:
foo
*
bar
Lines:
foo
bats-bug.bats
some-file
bar
1 test, 1 failure
I can send a PR to use while read
instead, assuming there's no reason this behavior is intended (e.g. backwards compatibility).
Dr-Terrible and karakartal1881
Metadata
Metadata
Assignees
Labels
Component: Bash CodeEverything regarding the bash codeEverything regarding the bash codePriority: CriticalBroken behavior in nearly all environments, e.g. wrong test results, internal bats errorBroken behavior in nearly all environments, e.g. wrong test results, internal bats errorStatus: ConfirmedThe reproducer worked as describedThe reproducer worked as describedType: Bug