[Pkg-puppet-devel] [facter] 67/352: (#23368) Quote scripts that contain spaces
Stig Sandbeck Mathisen
ssm at debian.org
Sun Apr 6 22:21:32 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 5b745a728c8a6e89a39e1677051898a080e4c1fe
Author: Josh Cooper <josh at puppetlabs.com>
Date: Thu Dec 5 23:18:42 2013 -0800
(#23368) Quote scripts that contain spaces
The Facter::Util::Resolution.exec method expects that commands with
spaces are quoted. On 2003, external facts are typically under
C:\Documents and Settings\All Users\Application Data. As a result,
facter would always fail to execute external executable facts on 2003.
This is not an issue on 2008 and up, because external facts are
typically located under C:\ProgramData.
This is not an issue for powershell scripts, because we pass the quoted
name of the script to powershell.
This is not an issue for text based external facts, because `File.read`
do not require paths with spaces to be quoted (since its not a command
and possibly arguments, or just a command with spaces).
This commit adds a `quote` method to the ScriptParser so that we quote
the script if it has spaces.
---
lib/facter/util/parser.rb | 8 +++++++-
spec/unit/util/parser_spec.rb | 8 ++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/lib/facter/util/parser.rb b/lib/facter/util/parser.rb
index cf3305a..1f87134 100644
--- a/lib/facter/util/parser.rb
+++ b/lib/facter/util/parser.rb
@@ -119,7 +119,13 @@ module Facter::Util::Parser
class ScriptParser < Base
def parse_results
- KeyValuePairOutputFormat.parse Facter::Util::Resolution.exec(filename)
+ KeyValuePairOutputFormat.parse Facter::Util::Resolution.exec(quote(filename))
+ end
+
+ private
+
+ def quote(filename)
+ filename.index(' ') ? "\"#{filename}\"" : filename
end
end
diff --git a/spec/unit/util/parser_spec.rb b/spec/unit/util/parser_spec.rb
index ccf4044..54bc1e4 100755
--- a/spec/unit/util/parser_spec.rb
+++ b/spec/unit/util/parser_spec.rb
@@ -120,6 +120,14 @@ describe Facter::Util::Parser do
expects_script_to_return(cmd, nil, {})
end
+ it "quotes scripts with spaces" do
+ path = "/h a s s p a c e s#{ext}"
+
+ Facter::Util::Resolution.expects(:exec).with("\"#{path}\"").returns(data_in_txt)
+
+ expects_script_to_return(path, data_in_txt, data)
+ end
+
context "exe, bat, cmd, and com files" do
let :cmds do ["/tmp/foo.bat", "/tmp/foo.cmd", "/tmp/foo.exe", "/tmp/foo.com"] 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