]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Prevent undefined method `split' for nil:NilClass with pe_foo_version facts
authorJeff McCune <jeff@puppetlabs.com>
Thu, 25 Oct 2012 17:00:42 +0000 (10:00 -0700)
committerJeff McCune <jeff@puppetlabs.com>
Thu, 25 Oct 2012 17:00:45 +0000 (10:00 -0700)
Without this patch the pe_major_version, pe_minor_version, and
pe_patch_version facts directly depend on the pe_version fact in a
manner that calls split directly on the return value.

This is a problem because Fact values are not always guaranteed to
return strings, or objects that respond to split.  This patch is a
defensive measure to ensure we're always calling the split method on a
string object.

If the Fact returns nil, this will be converted to an empty string
responding to split.

lib/facter/pe_version.rb

index 7c31e84c3cd5766c13cd436925602400b7aa6dda..0cc0f64e950d7be7da540d82069a4ff7c674e8e1 100644 (file)
@@ -28,20 +28,26 @@ end
 Facter.add("pe_major_version") do
   confine :is_pe => true
   setcode do
-    Facter.value(:pe_version).split('.')[0]
+    if pe_version = Facter.value(:pe_version)
+      pe_version.to_s.split('.')[0]
+    end
   end
 end
 
 Facter.add("pe_minor_version") do
   confine :is_pe => true
   setcode do
-    Facter.value(:pe_version).split('.')[1]
+    if pe_version = Facter.value(:pe_version)
+      pe_version.to_s.split('.')[1]
+    end
   end
 end
 
 Facter.add("pe_patch_version") do
   confine :is_pe => true
   setcode do
-    Facter.value(:pe_version).split('.')[2]
+    if pe_version = Facter.value(:pe_version)
+      pe_version.to_s.split('.')[2]
+    end
   end
 end