diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2008-12-19 15:05:29 +0100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-03-14 11:29:10 +1100 |
commit | 73a0757b559d7e4fbd1da43bbcf4e60fd9155896 (patch) | |
tree | fee97655c589893369fbc6308024054942b8966a /spec/unit/parser/scope.rb | |
parent | 84d6637cfc47a14114493254ec8e68f2887a93d8 (diff) | |
download | puppet-73a0757b559d7e4fbd1da43bbcf4e60fd9155896.tar.gz puppet-73a0757b559d7e4fbd1da43bbcf4e60fd9155896.tar.xz puppet-73a0757b559d7e4fbd1da43bbcf4e60fd9155896.zip |
Fix #1828 - Scope.number? wasn't strict enough and could produce wrong results
Some invalid numbers were treated as numbers and conversion to Integer
was failing returning 0 (for instance 0.24.7).
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec/unit/parser/scope.rb')
-rwxr-xr-x | spec/unit/parser/scope.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb index fa76c4ff2..13559528b 100755 --- a/spec/unit/parser/scope.rb +++ b/spec/unit/parser/scope.rb @@ -81,7 +81,21 @@ describe Puppet::Parser::Scope do Puppet::Parser::Scope.number?("0755").should == 0755 end + it "should return nil on malformed integers" do + Puppet::Parser::Scope.number?("0.24.5").should be_nil + end + + it "should convert strings with leading 0 to integer if they are not octal" do + Puppet::Parser::Scope.number?("0788").should == 788 + end + it "should convert strings of negative integers" do + Puppet::Parser::Scope.number?("-0788").should == -788 + end + + it "should return nil on malformed hexadecimal numbers" do + Puppet::Parser::Scope.number?("0x89g").should be_nil + end end end |