From 76ca35a095df5c17dff92ba91c4cc41d1a1037e7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 30 Jan 2013 22:17:10 -0800 Subject: [PATCH] Sanitize folder names for default virtualbox name [GH-1223] --- CHANGELOG.md | 1 + plugins/providers/virtualbox/action/default_name.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b3974ea0..b0ac012f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ IMPROVEMENTS / BUG FIXES: using SCP to upload files. [GH-924] - Box adding doesn't use `/tmp` anymore which can avoid some cross-device copy issues. [GH-1199] + - Vagrant works properly in folders with strange characters. [GH-1223] ## 1.0.6 (December 21, 2012) diff --git a/plugins/providers/virtualbox/action/default_name.rb b/plugins/providers/virtualbox/action/default_name.rb index 9ef89cf70..f1b0565dd 100644 --- a/plugins/providers/virtualbox/action/default_name.rb +++ b/plugins/providers/virtualbox/action/default_name.rb @@ -10,8 +10,12 @@ module VagrantPlugins end def call(env) - @logger.info("Setting the default name of the VM") - name = env[:root_path].basename.to_s + "_#{Time.now.to_i}" + # Figure out the name and sanitize the default + prefix = env[:root_path].basename.to_s + prefix.gsub!(/[^-a-z0-9_]/i, "") + name = prefix + "_#{Time.now.to_i}" + @logger.info("Setting the default name of the VM: #{name}") + env[:machine].provider.driver.set_name(name) @app.call(env)