summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-12-19 15:05:29 +0100
committerJames Turnbull <james@lovedthanlost.net>2008-12-27 12:46:58 +1100
commitbdee116d08e9ed9c5efcf94a92709c061a8b43c2 (patch)
tree487e3f7155ca420238d5b8ae19a63f22919394a9 /spec/unit/parser
parentd69abfeaade452845924a0d4446dc1ea85637fc7 (diff)
downloadpuppet-bdee116d08e9ed9c5efcf94a92709c061a8b43c2.tar.gz
puppet-bdee116d08e9ed9c5efcf94a92709c061a8b43c2.tar.xz
puppet-bdee116d08e9ed9c5efcf94a92709c061a8b43c2.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')
-rwxr-xr-xspec/unit/parser/scope.rb14
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