save_to_file macro does not work if the thing being saved contains a heredoc terminated with EOF
cat <<EOF >$file $content EOF
but if `$content` contains a heredoc terminated with `EOF`, it terminates the heredoc that save_to_file creates.
- Fixes #35530 - Make save_to_file macro safer
cat <<EOF >$file
but if `$content` contains a heredoc terminated with `EOF`, it
terminates the heredoc that save_to_file creates.
This fix prefixes each line of $content with a space and then pipes the
result into sed to trim the one leading space away.
- Fixes #35530 - Update snapshots
Refs #35530 - Alternative approach to save_to_file
save_to_macro generates a command using cat and a heredoc string.
However, if the content to be written contains a heredoc using the same
delimiter, save_to_macro's heredoc will be terminated by it, leading to
mangled parts of the original content and save_to_macro being left
Another issue is, that when the content to be written contains things
like shell variables or subprocesses, those get evaluated when the
content is being written out. This may be desirable in some cases and
surprising in others.
In this commit:
- delimiter suffix is based on a hash of the file being written
- be more explicit about when the file is truncated
- Allow optionally storing the content explicitly, without letting the
shell replace variables in it. Note, this requires base64 utility to
be available on the target machine.
- make the macro work with files with special characters in their names