Bug #32461
save_to_file() in templates cuts off last end of line
Description
I have noticed when I have two save_to_file() calls right after each other that save_to_file is cutting off the last end of line.
Example:
<%= save_to_file('/tmp/first_file', snippet('first_template')) %>
<%= save_to_file('/tmp/second_file', snippet('second_template')) %>
If there is not an extra empty line in the snippet passed to save_to_file, then you get something generated like this:
cat << EOF > /tmp/first_file
This is my first file
This is the last lineEOF
And if you have two calls to save_to_file right after each other, they will get put into the same file, because the EOF from the first file is not on a line by itself and you get something like this.
cat << EOF > /tmp/first_file
This is my first file
This is the last lineEOF
cat << EOF > /tmp/second_file
This is my second file
This is the last lineEOF
And the CONTENT of the generate file contains something like this due to the end of line being cutoff.
This is my first file
This is the last lineEOF
cat << EOF > /tmp/second_file
This is my second file
This is the last line
There is probably an extra trim or something being done to the snippet data being sent to save_to_file.
If I add an extra blank line onto all the snippets used with save_to_file then the EOF is alone on the last line as required.
Associated revisions
History
#1
Updated by The Foreman Bot over 1 year ago
- Assignee set to Lukas Zapletal
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/8488 added
#2
Updated by The Foreman Bot 9 months ago
- Fixed in Releases 3.2.0 added
#3
Updated by Lukas Zapletal 9 months ago
- Status changed from Ready For Testing to Closed
Applied in changeset foreman|638c4be8fa43e5277edd86e7c8002a3b100ba526.
#4
Updated by The Foreman Bot 8 months ago
- Pull request https://github.com/theforeman/foreman/pull/8976 added
#5
Updated by The Foreman Bot 8 months ago
- Fixed in Releases 3.1.1 added
#6
Updated by Amit Upadhye 8 months ago
- Fixed in Releases 3.1.0 added
- Fixed in Releases deleted (
3.1.1, 3.2.0)
#7
Updated by Amit Upadhye 8 months ago
- Category set to Templates
Fixes #32461 - add endline in save_to_file
Co-authored-by: Ondřej Ezr <ezrik12@gmail.com>