summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/ast/leaf.rb2
-rwxr-xr-xspec/unit/parser/ast/leaf.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 2f00ea78d..153120a34 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -102,7 +102,7 @@ class Puppet::Parser::AST
end
def to_classname
- to_s.downcase.gsub(/[^-a-zA-Z0-9:.]/,'').sub(/^\.+/,'')
+ to_s.downcase.gsub(/[^-\w:.]/,'').sub(/^\.+/,'')
end
# implementing eql? and hash so that when an HostName is stored
diff --git a/spec/unit/parser/ast/leaf.rb b/spec/unit/parser/ast/leaf.rb
index 69b704ad8..e9681503d 100755
--- a/spec/unit/parser/ast/leaf.rb
+++ b/spec/unit/parser/ast/leaf.rb
@@ -195,6 +195,16 @@ describe Puppet::Parser::AST::HostName do
host.to_classname.should == "klassname"
end
+ it "should preserve '_' in to_classname with a string nodename" do
+ host = Puppet::Parser::AST::HostName.new( :value => "node_with_underscore")
+ host.to_classname.should == "node_with_underscore"
+ end
+
+ it "should preserve '_' in to_classname with a regex nodename" do
+ host = Puppet::Parser::AST::HostName.new( :value => Puppet::Parser::AST::Regex.new(:value => "/\dnode_with_underscore\.+/") )
+ host.to_classname.should == "dnode_with_underscore."
+ end
+
it "should return a string usable as classname when calling to_classname" do
host = Puppet::Parser::AST::HostName.new( :value => Puppet::Parser::AST::Regex.new(:value => "/^this-is not@a classname$/") )
host.to_classname.should == "this-isnotaclassname"