[Pkg-puppet-devel] [facter] 255/352: (FACT-322) Remove fact special casing of empty string

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:51 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 40863af41562e67e85853c56c664946c8b0733c3
Author: Adrien Thebo <git at somethingsinistral.net>
Date:   Thu Feb 13 14:50:05 2014 -0800

    (FACT-322) Remove fact special casing of empty string
    
    When facts were evaluating resolutions, return values that were either
    the empty string or nil would be ignored. This commit removes the
    special casing on the empty string and fixes up some resolutions that
    were relying on the behavior.
---
 lib/facter/domain.rb        | 20 +++++++++++++-------
 lib/facter/util/fact.rb     |  6 +-----
 spec/unit/util/fact_spec.rb |  6 ------
 3 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/lib/facter/domain.rb b/lib/facter/domain.rb
index b8a4ae8..ac9aa68 100644
--- a/lib/facter/domain.rb
+++ b/lib/facter/domain.rb
@@ -64,8 +64,10 @@ Facter.add(:domain) do
       return_value ||= domain
       return_value ||= search
     end
-    return_value = '' if return_value.nil?
-    return_value.gsub(/\.$/, '')
+
+    if return_value
+      return_value.gsub(/\.$/, '')
+    end
   end
 end
 
@@ -73,10 +75,13 @@ Facter.add(:domain) do
   confine :kernel => :windows
   setcode do
     require 'facter/util/registry'
-    domain = ""
+
+    domain = nil
     regvalue = Facter::Util::Registry.hklm_read('SYSTEM\CurrentControlSet\Services\Tcpip\Parameters', 'Domain')
-    domain = regvalue if regvalue
-    if domain == ""
+
+    if regvalue and not regvalue.empty?
+      domain = regvalue
+    else
       require 'facter/util/wmi'
       Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic|
         if nic.DNSDomain && nic.DNSDomain.length > 0
@@ -86,8 +91,9 @@ Facter.add(:domain) do
       }
     end
 
-    domain ||= ''
 
-    domain.gsub(/\.$/, '')
+    if domain
+      domain.gsub(/\.$/, '')
+    end
   end
 end
diff --git a/lib/facter/util/fact.rb b/lib/facter/util/fact.rb
index 587bd33..0224ffc 100644
--- a/lib/facter/util/fact.rb
+++ b/lib/facter/util/fact.rb
@@ -158,7 +158,7 @@ class Facter::Util::Fact
 
   def find_first_real_value(resolutions)
     resolutions.each do |resolve|
-      value = normalize_value(resolve.value)
+      value = resolve.value
       if not value.nil?
         return value
       end
@@ -178,10 +178,6 @@ class Facter::Util::Fact
     end
   end
 
-  def normalize_value(value)
-    value == "" ? nil : value
-  end
-
   def create_or_return_resolution(resolution_name, resolution_type)
     resolve = self.resolution(resolution_name)
 
diff --git a/spec/unit/util/fact_spec.rb b/spec/unit/util/fact_spec.rb
index f3aebef..1aa1822 100755
--- a/spec/unit/util/fact_spec.rb
+++ b/spec/unit/util/fact_spec.rb
@@ -122,12 +122,6 @@ describe Facter::Util::Fact do
 
       expect(fact.value).to eq "1"
     end
-
-    it "returns nil if the value is the empty string" do
-      fact.add { setcode { "" } }
-
-      expect(fact.value).to be_nil
-    end
   end
 
   describe '#flush' do

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list