From 73a0757b559d7e4fbd1da43bbcf4e60fd9155896 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 19 Dec 2008 15:05:29 +0100 Subject: 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 --- spec/unit/parser/scope.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/unit/parser/scope.rb') 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 -- cgit