From f7407baf9df38f5f2f58e1e676e710411fb49f7b Mon Sep 17 00:00:00 2001 From: Claire McQuin Date: Wed, 24 Sep 2014 10:54:47 -0700 Subject: Add spec for escape_glob with multiple path parts. --- lib/chef/util/path_helper.rb | 2 +- spec/unit/util/path_helper_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/chef/util/path_helper.rb b/lib/chef/util/path_helper.rb index 3dde7b1887..8ca8279593 100644 --- a/lib/chef/util/path_helper.rb +++ b/lib/chef/util/path_helper.rb @@ -138,7 +138,7 @@ class Chef # to be escaped before globbing can be done. # http://stackoverflow.com/questions/14127343 def self.escape_glob(*parts) - path = cleanpath(join(parts)) + path = cleanpath(join(*parts)) path.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\"+x } end end diff --git a/spec/unit/util/path_helper_spec.rb b/spec/unit/util/path_helper_spec.rb index 26bdf3ad91..1d97efc607 100644 --- a/spec/unit/util/path_helper_spec.rb +++ b/spec/unit/util/path_helper_spec.rb @@ -223,5 +223,19 @@ describe Chef::Util::PathHelper do escaped_path = "C:\\\\this\\\\\\*path\\\\\\[needs\\]\\\\escaping\\?" expect(PathHelper.escape_glob(path)).to eq(escaped_path) end + + context "when given more than one argument" do + it "joins, cleanpaths, and escapes characters reserved by glob" do + args = ["this/*path", "[needs]", "escaping?"] + escaped_path = if windows? + "this\\\\\\*path\\\\\\[needs\\]\\\\escaping\\?" + else + "this/\\*path/\\[needs\\]/escaping\\?" + end + expect(PathHelper).to receive(:join).with(*args).and_call_original + expect(PathHelper).to receive(:cleanpath).and_call_original + expect(PathHelper.escape_glob(*args)).to eq(escaped_path) + end + end end end -- cgit v1.2.1