diff options
author | Markus Roberts <Markus@reality.com> | 2009-09-04 16:10:20 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-09-05 09:33:14 +1000 |
commit | 42ab73f29ada8e045e6638ccb454b12595220fe1 (patch) | |
tree | 667bab2c5e9944b70c3abf95b572c7620033d899 | |
parent | a0f0dccb0f42140b9e1cec0cc551b3860c7089c1 (diff) | |
download | puppet-42ab73f29ada8e045e6638ccb454b12595220fe1.tar.gz puppet-42ab73f29ada8e045e6638ccb454b12595220fe1.tar.xz puppet-42ab73f29ada8e045e6638ccb454b12595220fe1.zip |
Ticket #2525 don't fail find_manifest on invalid module names
The patch that put validity assertions in for module names broke
find_manifest because rather than returning a failure it now rasies
an exception. This patch catches the exception and treats it as
a negative result.
Signed-off-by: Markus Roberts <Markus@reality.com>
-rw-r--r-- | lib/puppet/module.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/files.rb | 24 |
2 files changed, 12 insertions, 14 deletions
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb index d332392f9..9aa634bc5 100644 --- a/lib/puppet/module.rb +++ b/lib/puppet/module.rb @@ -141,6 +141,6 @@ class Puppet::Module end def assert_validity - raise InvalidName unless name =~ /^[\w-]+$/ + raise InvalidName unless name =~ /^[-\w]+$/ end end diff --git a/lib/puppet/parser/files.rb b/lib/puppet/parser/files.rb index 749428e9f..3442e11a6 100644 --- a/lib/puppet/parser/files.rb +++ b/lib/puppet/parser/files.rb @@ -16,10 +16,13 @@ module Puppet::Parser::Files def find_manifests(start, options = {}) cwd = options[:cwd] || Dir.getwd module_name, pattern = split_file_path(start) - if mod = Puppet::Module.find(module_name, options[:environment]) - return mod.match_manifests(pattern) + begin + if mod = Puppet::Module.find(module_name, options[:environment]) + return mod.match_manifests(pattern) + end + rescue Puppet::Module::InvalidName + # Than that would be a "no." end - abspat = File::expand_path(start, cwd) files = Dir.glob(abspat).reject { |f| FileTest.directory?(f) } if files.size == 0 @@ -79,16 +82,11 @@ module Puppet::Parser::Files end end - # Split the path into the module and the rest of the path. - # This method can and often does return nil, so anyone calling - # it needs to handle that. + # Split the path into the module and the rest of the path, or return + # nil if the path is empty or absolute (starts with a /). + # This method can return nil & anyone calling it needs to handle that. def split_file_path(path) - if path =~ %r/^#{File::SEPARATOR}/ - return nil - end - - modname, rest = path.split(File::SEPARATOR, 2) - return nil if modname.nil? || modname.empty? - return modname, rest + path.split(File::SEPARATOR, 2) unless path =~ /^(#{File::SEPARATOR}|$)/ end + end |