Skip to content

Commit

Permalink
Escape quoted values in headers for cURL
Browse files Browse the repository at this point in the history
Closes #101
  • Loading branch information
oestrich committed Nov 26, 2013
1 parent d48c626 commit efcb61e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/rspec_api_documentation/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def post_data
private
def format_header(header, value)
formatted_header = header.gsub(/^HTTP_/, '').titleize.split.join("-")
"#{formatted_header}: #{value}"
formatted_value = value.gsub(/"/, "\\\"")
"#{formatted_header}: #{formatted_value}"
end
end
end
9 changes: 8 additions & 1 deletion spec/curl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
let(:method) { "POST" }
let(:path) { "/orders" }
let(:data) { "order%5Bsize%5D=large&order%5Btype%5D=cart" }
let(:headers) { {"HTTP_ACCEPT" => "application/json", "HTTP_X_HEADER" => "header"} }
let(:headers) do
{
"HTTP_ACCEPT" => "application/json",
"HTTP_X_HEADER" => "header",
"HTTP_AUTHORIZATION" => %{Token token="mytoken"}
}
end

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

it "should call post" do
curl.should_receive(:post)
Expand Down

0 comments on commit efcb61e

Please sign in to comment.