Skip to content

Commit

Permalink
Validate that commands only contain proper characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed May 6, 2012
1 parent 64ece50 commit e4fa5bb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/vagrant/plugin/v1.rb
Expand Up @@ -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.
Expand Down Expand Up @@ -66,6 +73,11 @@ def self.action_hook(name, &block)
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

Expand Down

0 comments on commit e4fa5bb

Please sign in to comment.