[Pkg-puppet-devel] [facter] 127/180: (#190) Fix file expansion crash when $HOME is not set.

Stig Sandbeck Mathisen ssm at debian.org
Mon Jun 30 15:06:39 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 bd53a427b62f2a72e82aab92cbfa15dcfc15f246
Author: Cassiano Leal <cassiano.leal at gamesys.co.uk>
Date:   Wed May 21 17:33:58 2014 +0100

    (#190) Fix file expansion crash when $HOME is not set.
    
    Without this patch, when facter is run in an environment where $HOME
    is not set, it crashes while trying to expand_path "~". The patch
    uses Ruby's ENV['HOME'] instead of "~", which sanitises the
    expansion.
---
 lib/facter/util/config.rb     | 2 +-
 spec/unit/util/config_spec.rb | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/facter/util/config.rb b/lib/facter/util/config.rb
index 0db5a9d..1d244a8 100644
--- a/lib/facter/util/config.rb
+++ b/lib/facter/util/config.rb
@@ -46,7 +46,7 @@ module Facter::Util::Config
         @external_facts_dirs = [File.join(windows_dir, 'PuppetLabs', 'facter', 'facts.d')]
       end
     else
-      @external_facts_dirs = [File.expand_path(File.join("~", ".facter", "facts.d"))]
+      @external_facts_dirs = [File.expand_path(File.join("#{ENV['HOME']}", ".facter", "facts.d"))]
     end
   end
 
diff --git a/spec/unit/util/config_spec.rb b/spec/unit/util/config_spec.rb
index 830eb09..7da1f3f 100644
--- a/spec/unit/util/config_spec.rb
+++ b/spec/unit/util/config_spec.rb
@@ -5,6 +5,11 @@ require 'spec_helper'
 describe Facter::Util::Config do
   include PuppetlabsSpec::Files
 
+  it "should not crash when there's no $HOME set on the environment" do
+    ENV['HOME'] = nil
+    lambda { Facter::Util::Config.setup_default_ext_facts_dirs }.should_not raise_exception
+  end
+
   describe "is_windows? function" do
     it "should detect windows if Ruby RbConfig::CONFIG['host_os'] returns a windows OS" do
       host_os = ["mswin","win32","dos","mingw","cygwin"]

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