Skip to content

Commit efcb61e

Browse files
committed
Escape quoted values in headers for cURL
Closes #101
1 parent d48c626 commit efcb61e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/rspec_api_documentation/curl.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def post_data
5555
private
5656
def format_header(header, value)
5757
formatted_header = header.gsub(/^HTTP_/, '').titleize.split.join("-")
58-
"#{formatted_header}: #{value}"
58+
formatted_value = value.gsub(/"/, "\\\"")
59+
"#{formatted_header}: #{formatted_value}"
5960
end
6061
end
6162
end

spec/curl_spec.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99
let(:method) { "POST" }
1010
let(:path) { "/orders" }
1111
let(:data) { "order%5Bsize%5D=large&order%5Btype%5D=cart" }
12-
let(:headers) { {"HTTP_ACCEPT" => "application/json", "HTTP_X_HEADER" => "header"} }
12+
let(:headers) do
13+
{
14+
"HTTP_ACCEPT" => "application/json",
15+
"HTTP_X_HEADER" => "header",
16+
"HTTP_AUTHORIZATION" => %{Token token="mytoken"}
17+
}
18+
end
1319

1420
it { should =~ /^curl/ }
1521
it { should =~ /http:\/\/example\.com\/orders/ }
1622
it { should =~ /-d 'order%5Bsize%5D=large&order%5Btype%5D=cart'/ }
1723
it { should =~ /-X POST/ }
1824
it { should =~ /-H "Accept: application\/json"/ }
1925
it { should =~ /-H "X-Header: header"/ }
26+
it { should =~ /-H "Authorization: Token token=\\"mytoken\\""/ }
2027

2128
it "should call post" do
2229
curl.should_receive(:post)

0 commit comments

Comments
 (0)