diff --git a/CHANGELOG.md b/CHANGELOG.md index 72b46c3ab..f03466c82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ BUG FIXES: - core: Cleanup all temp files. [GH-4103] - core: User curlrc is not loaded, preventing strange download issues. [GH-4328] + - core: VM names may no longer contain brackets, since they cause + issues with some providers. [GH-4319] - commands/package: base package won't crash with exception [GH-4017] - commands/rsync-auto: Destroyed machines won't raise exceptions. [GH-4031] - communicators/ssh: Nicer error if remote unexpectedly disconects. [GH-4038] diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index c152c45ba..d12a11891 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -660,6 +660,15 @@ module VagrantPlugins end end + # Validate sub-VMs if there are any + @__defined_vms.each do |name, _| + if name =~ /[\[\]\{\}]/ + errors["vm"] << I18n.t( + "vagrant.config.vm.name_invalid", + name: name) + end + end + errors end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 5b57d99b9..dbf50f258 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1250,6 +1250,8 @@ en: hostname_invalid_characters: |- The hostname set for the VM should only contain letters, numbers, hyphens or dots. It cannot start with a hyphen or dot. + name_invalid: |- + The sub-VM name '%{name}' is invalid. Please don't use special characters. network_ip_ends_in_one: |- You assigned a static IP ending in ".1" to this machine. This is very often used by the router and can cause the diff --git a/test/unit/plugins/kernel_v2/config/vm_test.rb b/test/unit/plugins/kernel_v2/config/vm_test.rb index cd202d1f3..6b24ac47b 100644 --- a/test/unit/plugins/kernel_v2/config/vm_test.rb +++ b/test/unit/plugins/kernel_v2/config/vm_test.rb @@ -121,6 +121,27 @@ describe VagrantPlugins::Kernel_V2::VMConfig do end end + describe "#define" do + it "should allow regular names" do + subject.define "foo" + subject.finalize! + + assert_valid + end + + [ + "foo [1]", + "bar {2}", + ].each do |name| + it "should disallow names with brackets" do + subject.define name + subject.finalize! + + assert_invalid + end + end + end + describe "#guest" do it "is nil by default" do subject.finalize!