From 2c66c3579222e85a040c9202df14c52a2da69f71 Mon Sep 17 00:00:00 2001 From: Jan Berdajs Date: Tue, 19 Mar 2013 22:36:04 +0100 Subject: [PATCH 1/2] escape quotes in curl data (fixes https://github.com/zipmark/rspec_api_documentation/issues/58 ) --- lib/rspec_api_documentation/curl.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rspec_api_documentation/curl.rb b/lib/rspec_api_documentation/curl.rb index 606fdfab..53f97317 100644 --- a/lib/rspec_api_documentation/curl.rb +++ b/lib/rspec_api_documentation/curl.rb @@ -40,7 +40,8 @@ def get_data end def post_data - "-d \"#{data}\"" + escaped_data = data.gsub("'", "\\u0027") + "-d '#{escaped_data}'" end private From 9a90a64631ada3a49cceee9fc5e6412a5d269453 Mon Sep 17 00:00:00 2001 From: MrBrdo Date: Tue, 19 Mar 2013 23:03:33 +0100 Subject: [PATCH 2/2] fix specs, coerce data into string (i.e. handle nil case) --- lib/rspec_api_documentation/curl.rb | 2 +- spec/curl_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rspec_api_documentation/curl.rb b/lib/rspec_api_documentation/curl.rb index 53f97317..bbd1a763 100644 --- a/lib/rspec_api_documentation/curl.rb +++ b/lib/rspec_api_documentation/curl.rb @@ -40,7 +40,7 @@ def get_data end def post_data - escaped_data = data.gsub("'", "\\u0027") + escaped_data = data.to_s.gsub("'", "\\u0027") "-d '#{escaped_data}'" end diff --git a/spec/curl_spec.rb b/spec/curl_spec.rb index aeb38172..bbefec3e 100644 --- a/spec/curl_spec.rb +++ b/spec/curl_spec.rb @@ -13,7 +13,7 @@ it { should =~ /^curl/ } it { should =~ /http:\/\/example\.com\/orders/ } - it { should =~ /-d "order%5Bsize%5D=large&order%5Btype%5D=cart"/ } + 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"/ } @@ -50,7 +50,7 @@ it { should =~ /^curl/ } it { should =~ /http:\/\/example\.com\/orders\/1/ } - it { should =~ /-d "size=large"/ } + it { should =~ /-d 'size=large'/ } it { should =~ /-X PUT/ } it { should =~ /-H "Accept: application\/json"/ } it { should =~ /-H "X-Header: header"/ }