fix(data_set): preservation of trailing whitespace#498
Merged
Chemaclass merged 2 commits intoOct 4, 2025
Merged
Conversation
Prior to this change, data_set was not preserving trailing whitespace in its
final argument. For example, data_set "value " or data_set "value " would
lose one space by the time the test function received the values.
Adding an empty string sentinel ('') at the end of data_set output ensures
there's always something after the last real argument, preventing bash from
trimming its trailing whitespace during word splitting.
mattness
commented
Oct 3, 2025
| done | ||
| printf '\n' | ||
| printf ' %q\n' "" | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This could be made more succinct with the following, but I chose not to do so in order to minimize what changed.
function data_set() {
for arg in "${@}"; do
printf '%q ' "${arg}"
done
printf '%q\n' "" # Sentinel
}
Member
There was a problem hiding this comment.
Feel free to work on this refactoring in a follow up PR if you want 🧠
Fixed "unbound variable" error when accessing array elements with
negative indices under set -u (nounset mode). Changed from using
args[-1] to calculating the last index explicitly and using a
positive index, which is compatible with strict error checking
Chemaclass
approved these changes
Oct 4, 2025
Contributor
Author
|
Bash 3.x got me! Thanks for the fix :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📚 Description
Fixes #497
Problem
data_setwas not preserving trailing whitespace in its final argument. For example,data_set "value "ordata_set "value "would lose lose one space by the time the test function received the valuesRoot Cause
The issue occurred in how
data_setoutput was parsed. When usingeval "args=($output)"to split the escaped arguments back into an array, bash's word splitting would trim trailing whitespace from the last element because there was nothing after it to delimit where it ended.Solution
Added an empty string sentinel (
'') at the end ofdata_setoutput. This ensures there's always something after the last real argument, preventing bash from trimming its trailing whitespace during word splitting.🔖 Changes
data_setto append an empty sentinel:printf '%q\n' ""runner::parse_data_provider_argsto remove the sentinel after parsing*, |, &, ;) that could breakeval, falling back to character-by-character parsing when needed✅ To-do list
CHANGELOG.mdto reflect the new feature or fix