Test command name validation and fix up some bugs
This commit is contained in:
parent
e4fa5bb489
commit
c2649074c3
|
@ -73,13 +73,15 @@ module Vagrant
|
|||
def self.command(name=UNSET_VALUE, &block)
|
||||
data[:command] ||= Registry.new
|
||||
|
||||
if name != UNSET_VALUE
|
||||
# Validate the name of the command
|
||||
if name.to_s !~ /^[-a-z0-9]/i
|
||||
if name.to_s !~ /^[-a-z0-9]+$/i
|
||||
raise InvalidCommandName, "Commands can only contain letters, numbers, and hyphens"
|
||||
end
|
||||
|
||||
# Register a new command class only if a name was given.
|
||||
data[:command].register(name.to_sym, &block) if name != UNSET_VALUE
|
||||
data[:command].register(name.to_sym, &block)
|
||||
end
|
||||
|
||||
# Return the registry
|
||||
data[:command]
|
||||
|
|
|
@ -44,6 +44,15 @@ describe Vagrant::Plugin::V1 do
|
|||
plugin.command[:foo].should == "bar"
|
||||
end
|
||||
|
||||
["spaces bad", "sym^bols"].each do |bad|
|
||||
it "should not allow bad command name: #{bad}" do
|
||||
plugin = Class.new(described_class)
|
||||
|
||||
expect { plugin.command(bad) {} }.
|
||||
to raise_error(Vagrant::Plugin::V1::InvalidCommandName)
|
||||
end
|
||||
end
|
||||
|
||||
it "should lazily register command classes" do
|
||||
# Below would raise an error if the value of the command class was
|
||||
# evaluated immediately. By asserting that this does not raise an
|
||||
|
|
Loading…
Reference in New Issue