vendored/puppet/lib/puppet/pops/evaluator/runtime3_converter.rb in bolt-0.23.0 vs vendored/puppet/lib/puppet/pops/evaluator/runtime3_converter.rb in bolt-0.24.0

- old
+ new

@@ -59,11 +59,11 @@ def convert(o, scope, undef_value) @convert_visitor.visit_this_2(self, o, scope, undef_value) end def convert_NilClass(o, scope, undef_value) - @inner ? :undef : undef_value + @inner ? nil : undef_value end def convert_Integer(o, scope, undef_value) return o unless o < MIN_INTEGER || o > MAX_INTEGER range_end = o > MAX_INTEGER ? 'max' : 'min' @@ -76,12 +76,14 @@ return f unless f != o raise Puppet::Error, "Use of a Ruby BigDecimal value outside Puppet Float range, got '#{o}'" end def convert_String(o, scope, undef_value) - # although wasteful, needed because user code may mutate these strings in Resources - o.frozen? ? o.dup : o + # Although wasteful, a dup is needed because user code may mutate these strings when applying + # Resources. This does not happen when in master mode since it only uses Resources that are + # in puppet core and those are all safe. + o.frozen? && !Puppet.run_mode.master? ? o.dup : o end def convert_Object(o, scope, undef_value) o end @@ -101,11 +103,12 @@ def convert_Iterator(o, scope, undef_value) raise Puppet::Error, _('Use of an Iterator is not supported here') end def convert_Symbol(o, scope, undef_value) - o == :undef && !@inner ? undef_value : o + o == :undef ? undef_value : o + #o == :undef && !@inner ? undef_value : o end def convert_PAnyType(o, scope, undef_value) o end @@ -192,9 +195,25 @@ end def convert_Timestamp(o, scope, undef_value) # Puppet 3x cannot handle Timestamps. Use the string form o.to_s + end + + # Converts result back to 4.x by replacing :undef with nil in Array and Hash objects + # + def self.convert_return(val3x) + if val3x == :undef + nil + elsif val3x.is_a?(Array) + val3x.map {|v| convert_return(v) } + elsif val3x.is_a?(Hash) + hsh = {} + val3x.each_pair {|k,v| hsh[convert_return(k)] = convert_return(v)} + hsh + else + val3x + end end @instance = self.new end