Skip to content

Commit

Permalink
fix ENC 'echo' script template to prevent expansion
Browse files Browse the repository at this point in the history
Currently the template script for creating the 'echo' script used for
ENC data wraps the data provided by the actual ENC in `cat <<-EOF`,
which causes the enclosed data to be variable-expanded, escape
characters (like double backslashes) to be replaced with their
concrete representations, etc.

This breaks things horribly if you have (e.g.) JSON data with
escaped strings (`"C:\\Windows"`), which will be processed and
output without those escapes (`"C:\Windows"`), which is invalid,
and definitely not what the user intended under any circumstance.

Using the 'quoted' variant of shell heredocs (`cat <<-'EOF'`) stops
this expansion.
  • Loading branch information
elfchief committed Jul 2, 2021
1 parent 5071b97 commit c433656
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/octocatalog-diff/catalog-util/builddir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def install_enc(logger)
enc_path = File.join(@tempdir, 'enc.sh')
File.open(enc_path, 'w') do |f|
f.write "#!/bin/sh\n"
f.write "cat <<-EOF\n"
f.write "cat <<-'EOF'\n"
f.write enc_obj.content
f.write "\nEOF\n"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/octocatalog-diff/tests/catalog-util/builddir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(options, logger)
enc = File.join(testobj.tempdir, 'enc.sh')
expect(File.file?(enc)).to eq(true)
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-EOF\n---\n\nEOF\n")
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-'EOF'\n---\n\nEOF\n")
end
end

Expand Down

0 comments on commit c433656

Please sign in to comment.