Ensure no new line chars in envs
This commit is contained in:
@@ -14,6 +14,8 @@ module EnvironmentWriter
|
|||||||
def modify_env(file, name, value)
|
def modify_env(file, name, value)
|
||||||
return if value.nil?
|
return if value.nil?
|
||||||
|
|
||||||
|
raise ArgumentError, "Invalid input: #{name}=#{value}" if value.include?("\n")
|
||||||
|
|
||||||
File.open(ENV[file], "a") do |f|
|
File.open(ENV[file], "a") do |f|
|
||||||
f.puts "#{name}=#{value}"
|
f.puts "#{name}=#{value}"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ RSpec.describe EnvironmentWriter do
|
|||||||
|
|
||||||
it { expect { subject }.not_to change { File.read(ENV["GITHUB_OUTPUT"], chomp: true).last } }
|
it { expect { subject }.not_to change { File.read(ENV["GITHUB_OUTPUT"], chomp: true).last } }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when value contains a newline" do
|
||||||
|
let(:value) { "var_value\n" }
|
||||||
|
|
||||||
|
it { expect { subject }.to raise_error(ArgumentError) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#set_environment" do
|
describe "#set_environment" do
|
||||||
@@ -39,5 +45,11 @@ RSpec.describe EnvironmentWriter do
|
|||||||
|
|
||||||
it { expect { subject }.not_to change { File.read(ENV["GITHUB_ENV"], chomp: true).last } }
|
it { expect { subject }.not_to change { File.read(ENV["GITHUB_ENV"], chomp: true).last } }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when value contains a newline" do
|
||||||
|
let(:value) { "env_var_value\n" }
|
||||||
|
|
||||||
|
it { expect { subject }.to raise_error(ArgumentError) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user