[Pkg-puppet-devel] [facter] 52/352: (#22622) External output defaults to empty string

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:30 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 d81601f269768b890e8a48705a4d67db18b3177d
Author: Iristyle <Iristyle at github>
Date:   Mon Dec 2 15:58:36 2013 -0500

    (#22622) External output defaults to empty string
    
     - Previously, if an external fact generated empty output, parse would
       be called with a nil, which cannot have each_line called on it, and
       would cause Facter to crash.  This sets a reasonable default for
       external command output to the empty string
---
 lib/facter/util/parser.rb     |  2 ++
 spec/unit/util/parser_spec.rb | 15 ++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/lib/facter/util/parser.rb b/lib/facter/util/parser.rb
index 1b46908..7f9c514 100644
--- a/lib/facter/util/parser.rb
+++ b/lib/facter/util/parser.rb
@@ -68,6 +68,8 @@ module Facter::Util::Parser
 
   module KeyValuePairOutputFormat
     def self.parse(output)
+      return {} if output.nil?
+
       result = {}
       re = /^(.+?)=(.+)$/
       output.each_line do |line|
diff --git a/spec/unit/util/parser_spec.rb b/spec/unit/util/parser_spec.rb
index 11e55c1..ec53f60 100644
--- a/spec/unit/util/parser_spec.rb
+++ b/spec/unit/util/parser_spec.rb
@@ -76,7 +76,7 @@ describe Facter::Util::Parser do
       let(:data_in_txt) do "one=two\nthree=four\n" end
       it_behaves_like "txt parser"
     end
-    
+
     context "extra equal sign" do
       let(:data_in_txt) do "one=two\nthree=four=five\n" end
       let(:data) do {"one" => "two", "three" => "four=five"} end
@@ -109,6 +109,19 @@ describe Facter::Util::Parser do
       Facter::Util::Parser.parser_for(cmd).results.should be_nil
     end
 
+    context "with nil external script output" do
+      # ensure NothingParser is not used on Windows by tricking parser registration
+      if Facter::Util::Config.is_windows?
+        let :cmd do "/tmp/foo.bat" end
+      end
+      let :data_in_txt do nil end
+
+      it "should return an empty hash" do
+        File.stubs(:file?).with(cmd).returns(true)
+        Facter::Util::Parser.parser_for(cmd).results.should == {}
+      end
+    end
+
     context "on Windows" do
       let :cmd do "/tmp/foo.bat" end
 

-- 
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