diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-11 17:48:14 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-11 17:48:14 +0000 |
| commit | 373fb3b57c9edafc1935789d7b5cb99d45656f2e (patch) | |
| tree | cebfba070aafef332bb0ea49b758cbeed5cb41d9 | |
| parent | 8df349c61314d5bf0acc0402f90bb5399014d442 (diff) | |
| download | puppet-373fb3b57c9edafc1935789d7b5cb99d45656f2e.tar.gz puppet-373fb3b57c9edafc1935789d7b5cb99d45656f2e.tar.xz puppet-373fb3b57c9edafc1935789d7b5cb99d45656f2e.zip | |
Modifying "setclass" on scope to check the validity of class names, now that "set" can be used to set them manually, and added a test for it.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1104 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/puppet/parser/scope.rb | 4 | ||||
| -rwxr-xr-x | test/language/scope.rb | 17 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 27de8ffd8..7239feb17 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -631,6 +631,10 @@ module Puppet::Parser # hash. We store the object ID, not class name, so that we # can support multiple unrelated classes with the same name. def setclass(id, name) + unless name =~ /^[a-z]\w*$/ + raise Puppet::ParseError, "Invalid class name '%s'" % name + end + if self.topscope? @classtable[id] = name else diff --git a/test/language/scope.rb b/test/language/scope.rb index 06d244543..48689cd2e 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -546,4 +546,21 @@ class TestScope < Test::Unit::TestCase assert_equal("root", obj["owner"], "Owner did not take") assert_equal("755", obj["mode"], "Mode did not take") end + + def test_validclassnames + scope = Puppet::Parser::Scope.new() + + ["a-class", "a class", "Class", "a.class"].each do |bad| + assert_raise(Puppet::ParseError, "Incorrectly allowed %s" % bad.inspect) do + scope.setclass(object_id, bad) + end + end + + ["a_class", "class", "yayNess"].each do |good| + assert_nothing_raised("Incorrectly banned %s" % good.inspect) do + scope.setclass(object_id, good) + end + end + + end end |
