diff options
author | Tim Smith <tsmith@chef.io> | 2019-12-09 10:20:56 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-09 10:20:56 -0800 |
commit | f8c7ecbf7b9cbc49c3994a5b19336ca802c4c51e (patch) | |
tree | f3772ffe1b01cd565ecbde0e31d90b6dcca38567 | |
parent | e598e507599e6217b815a3082ca8a704681295cb (diff) | |
parent | d5700d3132e67cabc81da6db07b848f941040de2 (diff) | |
download | chef-f8c7ecbf7b9cbc49c3994a5b19336ca802c4c51e.tar.gz |
Merge pull request #9036 from MsysTechnologiesllc/VSingh/fix-apt-repository-resource-uri
Fix apt_repository uri single/double quotes and spaces
-rw-r--r-- | lib/chef/provider/apt_repository.rb | 3 | ||||
-rw-r--r-- | spec/unit/provider/apt_repository_spec.rb | 15 |
2 files changed, 11 insertions, 7 deletions
diff --git a/lib/chef/provider/apt_repository.rb b/lib/chef/provider/apt_repository.rb index 85fac1d2da..9443c58ef8 100644 --- a/lib/chef/provider/apt_repository.rb +++ b/lib/chef/provider/apt_repository.rb @@ -321,8 +321,7 @@ class Chef # @return [String] complete repo config text def build_repo(uri, distribution, components, trusted, arch, add_src = false) uri = make_ppa_url(uri) if is_ppa_url?(uri) - - uri = '"' + uri + '"' unless uri.start_with?("'", '"') + uri = URI.escape(uri) components = Array(components).join(" ") options = [] options << "arch=#{arch}" if arch diff --git a/spec/unit/provider/apt_repository_spec.rb b/spec/unit/provider/apt_repository_spec.rb index 11d505dad8..7537f2a9fb 100644 --- a/spec/unit/provider/apt_repository_spec.rb +++ b/spec/unit/provider/apt_repository_spec.rb @@ -226,27 +226,32 @@ C5986B4F1257FFA86632CBA746181433FBB75451 describe "#build_repo" do it "creates a repository string" do - target = %Q{deb "http://test/uri" unstable main\n} + target = "deb http://test/uri unstable main\n" expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil)).to eql(target) end + it "creates a repository string with spaces" do + target = "deb http://test/uri%20with%20spaces unstable main\n" + expect(provider.build_repo("http://test/uri with spaces", "unstable", "main", false, nil)).to eql(target) + end + it "creates a repository string with no distribution" do - target = %Q{deb "http://test/uri" main\n} + target = "deb http://test/uri main\n" expect(provider.build_repo("http://test/uri", nil, "main", false, nil)).to eql(target) end it "creates a repository string with source" do - target = %Q{deb "http://test/uri" unstable main\ndeb-src "http://test/uri" unstable main\n} + target = "deb http://test/uri unstable main\ndeb-src http://test/uri unstable main\n" expect(provider.build_repo("http://test/uri", "unstable", "main", false, nil, true)).to eql(target) end it "creates a repository string with options" do - target = %Q{deb [trusted=yes] "http://test/uri" unstable main\n} + target = "deb [trusted=yes] http://test/uri unstable main\n" expect(provider.build_repo("http://test/uri", "unstable", "main", true, nil)).to eql(target) end it "handles a ppa repo" do - target = %Q{deb "http://ppa.launchpad.net/chef/main/ubuntu" unstable main\n} + target = "deb http://ppa.launchpad.net/chef/main/ubuntu unstable main\n" expect(provider).to receive(:make_ppa_url).with("ppa:chef/main").and_return("http://ppa.launchpad.net/chef/main/ubuntu") expect(provider.build_repo("ppa:chef/main", "unstable", "main", false, nil)).to eql(target) end |