Fix trailing quotes in source path

This commit is contained in:
Chris Roberts 2018-10-08 14:18:30 -07:00
parent 904a712838
commit 412290828b
2 changed files with 23 additions and 0 deletions

View File

@ -52,6 +52,11 @@ module VagrantPlugins
raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp
end
# NOTE: We do this to handle paths on Windows like: "..\space dir\"
# because the final separater acts to escape the quote and ends up
# in the source value.
source = source.sub(/["']$/, "")
if File.file?(source)
type = :file
elsif File.directory?(source)

View File

@ -101,6 +101,24 @@ describe VagrantPlugins::CommandUpload::Command do
expect { subject.execute }.to raise_error(Vagrant::Errors::UploadSourceMissing)
end
context "when source path ends with double quote" do
let(:argv) { [".\\item\""] }
it "should remove trailing quote" do
expect(File).to receive(:file?).with(".\\item").and_return(true)
subject.execute
end
end
context "when source path ends with single quote" do
let(:argv) { ['.\item\''] }
it "should remove trailing quote" do
expect(File).to receive(:file?).with(".\\item").and_return(true)
subject.execute
end
end
context "when source is a directory" do
before do
allow(File).to receive(:file?).with("item").and_return(false)