]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Fix number of arguments check in flatten()
authorUwe Stuehler <ustuehler@team.mobile.de>
Tue, 23 Oct 2012 14:43:03 +0000 (16:43 +0200)
committerAdrien Thebo <git@somethingsinistral.net>
Mon, 18 Mar 2013 22:04:50 +0000 (15:04 -0700)
The function only uses the first argument, so raise an error with
too few arguments *and* with too many arguments.

lib/puppet/parser/functions/flatten.rb
spec/unit/puppet/parser/functions/flatten_spec.rb

index 781da7862d213c8442ee078826b5e97e15f01849..a1ed183290127914e65bbed54aa3aae2763086c3 100644 (file)
@@ -16,7 +16,7 @@ Would return: ['a','b','c']
   ) do |arguments|
 
     raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
-      "given (#{arguments.size} for 1)") if arguments.size < 1
+      "given (#{arguments.size} for 1)") if arguments.size != 1
 
     array = arguments[0]
 
index d4dfd2018651e6298c92873c7363baba4c6570dd..dba7a6bbdb1c243b22019e618fc8029561c926d5 100755 (executable)
@@ -11,6 +11,10 @@ describe "the flatten function" do
     lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError))
   end
 
+  it "should raise a ParseError if there is more than 1 argument" do
+    lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError))
+  end
+
   it "should flatten a complex data structure" do
     result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
     result.should(eq(["a","b","c","d","e","f","g"]))