Skip to content

Commit

Permalink
Merge pull request #968 from mrbuzz/fix-headers-containing-colon-char…
Browse files Browse the repository at this point in the history
…acters

Limit the number of splits when parsing headers in the Curb adapter
  • Loading branch information
bblimke committed Aug 2, 2022
2 parents 1c1a270 + cc93442 commit 524016e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webmock/http_lib_adapters/curb_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def build_request_signature
def headers_as_hash(headers)
if headers.is_a?(Array)
headers.inject({}) {|hash, header|
name, value = header.split(":").map(&:strip)
name, value = header.split(":", 2).map(&:strip)
hash[name] = value
hash
}
Expand Down
11 changes: 11 additions & 0 deletions spec/acceptance/curb/curb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,17 @@
expect(c.body).to eq("abc")
end

it "supports headers containing the ':' character" do
stub_request(:get, "www.example.com").with(headers: {'Referer'=>'http://www.example.com'}).to_return(body: "abc")

c = Curl::Easy.new
c.url = "http://www.example.com"
c.headers = ["Referer: http://www.example.com"]
c.http(:GET)
expect(c.body).to eq("abc")
expect(c.headers).to eq(["Referer: http://www.example.com"])
end

describe 'match request body' do
it 'for post' do
stub_request(:post, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc")
Expand Down

0 comments on commit 524016e

Please sign in to comment.