summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-07-13 12:27:37 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2018-07-13 12:27:37 -0700
commit24eefdbf89c332bde5853531fdd86f5f015d3dcd (patch)
tree5a31481b232fd99ee8183dc68a20cb4b8e5abebb
parentbb0dd117d50dd5b175387b753ce54b3ef6421017 (diff)
downloadchef-24eefdbf89c332bde5853531fdd86f5f015d3dcd.tar.gz
Fix duplicated query parameters
rubocop rule led to us mutating the argument to the constructor here and continuously appending query params. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/http/http_request.rb2
-rw-r--r--spec/unit/http/http_request_spec.rb8
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/chef/http/http_request.rb b/lib/chef/http/http_request.rb
index 9ee519c8ac..c38ac08133 100644
--- a/lib/chef/http/http_request.rb
+++ b/lib/chef/http/http_request.rb
@@ -152,7 +152,7 @@ class Chef
end
def configure_http_request(request_body = nil)
- req_path = (path).to_s
+ req_path = path.to_s.dup
req_path << "?#{query}" if query
@http_request = case method.to_s.downcase
diff --git a/spec/unit/http/http_request_spec.rb b/spec/unit/http/http_request_spec.rb
index 29562de021..c500c3b99e 100644
--- a/spec/unit/http/http_request_spec.rb
+++ b/spec/unit/http/http_request_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Klaas Jan Wierenga (<k.j.wierenga@gmail.com>)
-# Copyright:: Copyright 2014-2016, Chef Software, Inc.
+# Copyright:: Copyright 2014-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,6 +52,12 @@ describe Chef::HTTP::HTTPRequest do
expect(request.headers["Host"]).to eql("yourhost.com:8888")
end
+ it "should not mutate the URI when it contains parameters" do
+ # buggy constructor code mutated strings owned by the URI parameter
+ uri = URI("http://dummy.com/foo?bar=baz")
+ request = Chef::HTTP::HTTPRequest.new(:GET, uri, "")
+ expect(uri).to eql(URI("http://dummy.com/foo?bar=baz"))
+ end
end
context "with HTTPS url scheme" do