Skip to content

Commit 28d54b4

Browse files
committed
fix ENC 'echo' script template to prevent expansion
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.
1 parent 5071b97 commit 28d54b4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def install_enc(logger)
207207
enc_path = File.join(@tempdir, 'enc.sh')
208208
File.open(enc_path, 'w') do |f|
209209
f.write "#!/bin/sh\n"
210-
f.write "cat <<-EOF\n"
210+
f.write "cat <<-'EOF'\n"
211211
f.write enc_obj.content
212212
f.write "\nEOF\n"
213213
end

spec/octocatalog-diff/tests/catalog-util/builddir_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@
796796
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(options, logger)
797797
enc = File.join(testobj.tempdir, 'enc.sh')
798798
expect(File.file?(enc)).to eq(true)
799-
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-EOF\n---\n\nEOF\n")
799+
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-'EOF'\n---\n\nEOF\n")
800800
end
801801
end
802802

@@ -807,7 +807,7 @@
807807
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(options, logger)
808808
enc = File.join(testobj.tempdir, 'enc.sh')
809809
expect(File.file?(enc)).to eq(true)
810-
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-EOF\n---\n\nEOF\n")
810+
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-'EOF'\n---\n\nEOF\n")
811811
end
812812
end
813813

@@ -818,7 +818,7 @@
818818
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(options, logger)
819819
enc = File.join(testobj.tempdir, 'enc.sh')
820820
expect(File.file?(enc)).to eq(true)
821-
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-EOF\n---\n\nEOF\n")
821+
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-'EOF'\n---\n\nEOF\n")
822822
end
823823
end
824824

@@ -838,7 +838,7 @@
838838
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(options, logger)
839839
enc = File.join(testobj.tempdir, 'enc.sh')
840840
expect(File.file?(enc)).to eq(true)
841-
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-EOF\n---\nclasses:\n foo: {}\nparameters: {}\n\nEOF\n")
841+
expect(File.read(enc)).to eq("#!/bin/sh\ncat <<-'EOF'\n---\nclasses:\n foo: {}\nparameters: {}\n\nEOF\n")
842842
end
843843
end
844844
end

0 commit comments

Comments
 (0)