From 072becf6b51cb359d18b30d7eb01391f641dd840 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Mon, 21 Mar 2011 14:31:18 -0700 Subject: (#6806) Improve error checking and reporting for interface naming. We didn't do enough input checking and sanitization, and missed some edge-cases for naming interfaces. This adds testing, and cleans up some edge cases to handle things better. Reviewed-By: Pieter van de Bruggen --- lib/puppet/interface.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb index dfd75ef58..d169067ea 100644 --- a/lib/puppet/interface.rb +++ b/lib/puppet/interface.rb @@ -55,12 +55,12 @@ class Puppet::Interface remove_const(constantize(name)) rescue nil end - def self.unify_name(name) - name.to_s.downcase.to_sym - end - def self.constantize(name) - name.to_s.split(/\W|_/).map { |x| x.capitalize }.join + unless name.to_s =~ /^[-_a-z]+$/i then + raise ArgumentError, "#{name.inspect} (#{name.class}) is not a valid interface name" + end + + name.to_s.split(/[-_]/).map { |x| x.capitalize }.join end attr_accessor :default_format -- cgit