From 28a92850aba8b52cb363681e3557f84b3846ddae Mon Sep 17 00:00:00 2001 From: Erik Lattimore Date: Mon, 25 Sep 2017 15:14:56 -0400 Subject: [PATCH] Allow synced folders to contain spaces in the guest path It should be valid to allow paths with spaces for the synced folder guest path but since the guest path is used to generate the ID (if one isn't provided), this will err out in VirtualBox because it doesn't allow spaces for the --name argument. We should simply convert ' ' to '_' as we do with other special characters. --- plugins/providers/virtualbox/synced_folder.rb | 2 +- .../virtualbox/synced_folder_test.rb | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index 2ce0f82c1..a3eff1f29 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -85,7 +85,7 @@ module VagrantPlugins end def os_friendly_id(id) - id.gsub(/[\/\\]/,'_').sub(/^_/, '') + id.gsub(/[\s\/\\]/,'_').sub(/^_/, '') end # share_folders sets up the shared folder definitions on the diff --git a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb index 1cbb51edd..0e898991c 100644 --- a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb +++ b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb @@ -44,4 +44,30 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do it "should share the folders" end + + describe "os_friendly_id" do + it "should not replace normal chars" do + expect(subject.send(:os_friendly_id, 'perfectly_valid0_name')).to eq('perfectly_valid0_name') + end + + it "should replace spaces" do + expect(subject.send(:os_friendly_id, 'Program Files')).to eq('Program_Files') + end + + it "should replace leading underscore" do + expect(subject.send(:os_friendly_id, '_vagrant')).to eq('vagrant') + end + + it "should replace slash" do + expect(subject.send(:os_friendly_id, 'va/grant')).to eq('va_grant') + end + + it "should replace leading underscore and slash" do + expect(subject.send(:os_friendly_id, '/vagrant')).to eq('vagrant') + end + + it "should replace backslash" do + expect(subject.send(:os_friendly_id, 'foo\\bar')).to eq('foo_bar') + end + end end