Merge pull request #8875 from briancain/8716/master/dup-string-if-frozen-for-line-endings

Dup string if frozen for line endings
This commit is contained in:
Brian Cain 2017-08-15 10:04:34 -07:00 committed by GitHub
commit c0b54f74ea
2 changed files with 32 additions and 1 deletions

View File

@ -265,7 +265,7 @@ module VagrantPlugins
# or we're running on Windows.
if !config.binary && @machine.config.vm.communicator != :winrm
begin
script.gsub!(/\r\n?$/, "\n")
script = script.gsub(/\r\n?$/, "\n")
rescue ArgumentError
script = script.force_encoding("ASCII-8BIT").gsub(/\r\n?$/, "\n")
end

View File

@ -43,6 +43,37 @@ describe "Vagrant::Shell::Provisioner" do
end
end
context "with a script that was set to freeze the string" do
TEST_CONSTANT_VARIABLE = <<-TEST_CONSTANT_VARIABLE.freeze
echo test
TEST_CONSTANT_VARIABLE
let(:script) { TEST_CONSTANT_VARIABLE }
let(:config) {
double(
:config,
:args => "doesn't matter",
:env => {},
:upload_path => "arbitrary",
:remote? => false,
:path => nil,
:inline => script,
:binary => false,
)
}
it "does not raise an exception" do
vsp = VagrantPlugins::Shell::Provisioner.new(machine, config)
RSpec::Expectations.configuration.on_potential_false_positives = :nothing
# This test should be fine, since we are specifically looking for the
# string 'freeze' when RuntimeError is raised
expect {
vsp.provision
}.not_to raise_error(RuntimeError)
end
end
context "with remote script" do
context "that does not have matching sha1 checksum" do