From 96d19264b6f67848ab76c059fdbfad6f3040789e Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 1 May 2020 15:17:53 -0700 Subject: [PATCH] Automatically remove invalid file characters for disk name This commit copies what Vagrant does to filter out guest names with invalid characters, and applies the same regex to disk names. --- plugins/kernel_v2/config/disk.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/kernel_v2/config/disk.rb b/plugins/kernel_v2/config/disk.rb index 95b8005f3..f8bff732b 100644 --- a/plugins/kernel_v2/config/disk.rb +++ b/plugins/kernel_v2/config/disk.rb @@ -12,6 +12,8 @@ module VagrantPlugins DEFAULT_DISK_TYPES = [:disk, :dvd, :floppy].freeze + FILE_CHAR_REGEX = /[^-a-z0-9_]/i.freeze + # Note: This value is for internal use only # # @return [String] @@ -115,7 +117,10 @@ module VagrantPlugins @primary = false end - if @name == UNSET_VALUE + if @name.is_a?(String) && @name.match(FILE_CHAR_REGEX) + @logger.warn("Vagrant will remove detected invalid characters in '#{@name}' and convert the disk name into something usable for a file") + @name.gsub!(FILE_CHAR_REGEX, "") + elsif @name == UNSET_VALUE if @primary @name = "vagrant_primary" else