Validate that commands only contain proper characters

This commit is contained in:
Mitchell Hashimoto 2012-05-05 20:01:14 -07:00
parent 64ece507ad
commit e4fa5bb489
1 changed files with 12 additions and 0 deletions

View File

@ -4,6 +4,13 @@ module Vagrant
module Plugin
# The superclass for version 1 plugins.
class V1
# Exceptions that can be thrown within the plugin interface all
# inherit from this parent exception.
class Error < StandardError; end
# This is thrown when a command name given is invalid.
class InvalidCommandName < Error; end
LOGGER = Log4r::Logger.new("vagrant::plugin::v1")
# Returns a list of registered plugins for this version.
@ -66,6 +73,11 @@ module Vagrant
def self.command(name=UNSET_VALUE, &block)
data[:command] ||= Registry.new
# Validate the name of the command
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