Please review pull request #38: Bug fix to parse_string - extra_data doesn't get parsed when using hiera-puppet opened by (crayfishx)

Description:

When using hiera-puppet, if :undefined is returned then it wins the scope[var] || extra_data[var] and is later changed to "". This means when using puppet that extra_data[var] will never get evaluated but will when not using hiera-puppet. This breaks hiera-mysql which uses the extra_data hash to pass in the query key.

Issue was first raised here:

https://github.com/crayfishx/hiera-mysql/issues/2

This fix gets around the problem

  • Opened: Thu Apr 05 08:23:14 UTC 2012
  • Based on: puppetlabs:master (4b2ae058e9a60532886158af1ef8d7ce08118653)
  • Requested merge: crayfishx:master (0b929c0dd70ac39caecfa6240e3458f9a803f63e)

Diff follows:

diff --git a/lib/hiera/backend.rb b/lib/hiera/backend.rb
index e0c7c85..646e59f 100644
--- a/lib/hiera/backend.rb
+++ b/lib/hiera/backend.rb
@@ -88,10 +88,18 @@ def parse_string(data, scope, extra_data={})
         if tdata.is_a?(String)
           while tdata =~ /%\{(.+?)\}/
             var = $1
-            val = scope[var] || extra_data[var] || ""
 
-            # Puppet can return this for unknown scope vars
-            val = "" if val == :undefined
+            val = ""
+            
+            # Puppet can return :undefined for unknown scope vars, 
+            # If it does then we still need to evaluate extra_data
+            # before returning an empty string.
+            if scope[var] && scope[var] != :undefined
+                val = scope[var]
+            elsif extra_data[var]
+                val = extra_data[var]
+            end
+
 
             tdata.gsub!(/%\{#{var}\}/, val)
           end

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to