summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions/parsejson.rb
diff options
context:
space:
mode:
authorMorgan Haskel <morgan@puppetlabs.com>2015-09-21 10:56:08 -0700
committerMorgan Haskel <morgan@puppetlabs.com>2015-09-21 11:11:21 -0700
commit799c38e14e1583e676e2b25a9c1782fd40e29fff (patch)
treeca2f93dd6d459eac114f1e0b5cac05ac02d519cd /lib/puppet/parser/functions/parsejson.rb
parent9b1932c538354c1b360838c8cf7b942af314c99d (diff)
downloadpuppet-stdlib-799c38e14e1583e676e2b25a9c1782fd40e29fff.tar.gz
puppet-stdlib-799c38e14e1583e676e2b25a9c1782fd40e29fff.tar.bz2
Fix backwards compatibility from #511
Maintain the old behavior in the case where the optional second parameter isn't passed. Also, adding arity is backwards incompatible since stdlib still supports 2.7, so remove that.
Diffstat (limited to 'lib/puppet/parser/functions/parsejson.rb')
-rw-r--r--lib/puppet/parser/functions/parsejson.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/puppet/parser/functions/parsejson.rb b/lib/puppet/parser/functions/parsejson.rb
index f822fc4..b4af40e 100644
--- a/lib/puppet/parser/functions/parsejson.rb
+++ b/lib/puppet/parser/functions/parsejson.rb
@@ -3,7 +3,7 @@
#
module Puppet::Parser::Functions
- newfunction(:parsejson, :type => :rvalue, :arity => -2, :doc => <<-EOS
+ newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS
This function accepts JSON as a string and converts it into the correct
Puppet structure.
@@ -15,8 +15,12 @@ be returned if the parsing of YAML string have failed.
begin
PSON::load(arguments[0]) || arguments[1]
- rescue Exception
- arguments[1]
+ rescue Exception => e
+ if arguments[1]
+ arguments[1]
+ else
+ raise e
+ end
end
end