Snippets do not accurately reproduce the exact characters that were entered (tabs are replaced by spaces)
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
Sometimes it is critical that what we enter into a snippet is accurately represented. In this case, it is a shell script with a heredoc:
cat <<-EOF
-->a line of text
-->another line of text
-->EOF
However, when this snippet is downloaded using curl, the tabs are no longer present and the script fails.
Steps to reproduce
- Create a snippet containing:
#!/bin/bash
cat <<-EOF
-->a line of text
-->another line of text
-->EOF
Where --> is a literal tab character.
- Download the snippet using curl.
It doesn't matter how it is saved -o -O or redirect to a file.
curl "https://gitlab.com/api/v4/projects/:id/snippets/:id/raw" --header "PRIVATE-TOKEN: your_token"
- Run the script, it will fail because of the missing tab characters
You can examine the file and see that the tabs have been changed to spaces.
I am currently working around this by doing:
cat -t myfile.sh and taking that output and pasting it into the snippet.
Then when I download the script I pipe it through sed to convert back the tabs
curl "https://gitlab.com/api/v4/projects/:id/snippets/:id/raw" --header "PRIVATE-TOKEN: your_token" | sed -r 's/\^I/\t/g' > myfile.sh