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.
This commit is contained in:
Brian Cain 2020-05-01 15:17:53 -07:00
parent 4130cfe497
commit 96d19264b6
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0

View File

@ -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