Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid shell interpolation of re-run commands #268

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

Sam-Killgallon
Copy link
Contributor

@Sam-Killgallon Sam-Killgallon commented Mar 28, 2024

Recently had a leaky test which looked like;

test "It returns `foo`"

Which gave a message from ci-queue;

cat <<EOF |
MyTest#it_returns_`foo`
MyTest#other_test
EOF
bundle exec minitest-queue --queue - run -Itest test/my_test.rb

When this message is copy-pasted into the terminal it interpolates foo, tries to run the command and substitute the output. It gives an error message

zsh: command not found: foo

and results in an invalid invocation because the test name is turned into

MyTest#it_returns_

Adding quotes to the heredoc avoids interpolation and makes the heredoc a literal instead https://www.gnu.org/software/bash/manual/bash.html#Here-Documents

The format of here-documents is:

[n]<<[-]word
here-document
delimiter

No parameter and variable expansion, command substitution, arithmetic expansion, or filename expansion is performed on word. If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion

Adding quotes to the heredoc avoids interpolation when copy-pasted into a terminal.
https://www.gnu.org/software/bash/manual/bash.html#Here-Documents
@ChrisBr ChrisBr merged commit d96ed9f into main Mar 28, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants