From 348cf59ff0e11295c377e69ca8108dbc9ca531e4 Mon Sep 17 00:00:00 2001 From: ne-sachirou Date: Fri, 4 Oct 2019 13:31:14 +0900 Subject: [PATCH 1/4] bundler v1 is not installable. --- faraday-curl.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/faraday-curl.gemspec b/faraday-curl.gemspec index ad8083b..8d59e8d 100644 --- a/faraday-curl.gemspec +++ b/faraday-curl.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |spec| spec.add_dependency "faraday", ">= 0.9.0" - spec.add_development_dependency "bundler", "~> 1.6" + spec.add_development_dependency "bundler", "~> 2.0" spec.add_development_dependency "rake" spec.add_development_dependency 'rspec' spec.add_development_dependency 'faraday_middleware', ">= 0.9.0" From 11f31119bcf99c5ec0131752125ce84d599315fa Mon Sep 17 00:00:00 2001 From: ne-sachirou Date: Fri, 4 Oct 2019 13:38:34 +0900 Subject: [PATCH 2/4] Faraday ver. is changable. --- spec/curl_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/curl_spec.rb b/spec/curl_spec.rb index d465083..42812bb 100644 --- a/spec/curl_spec.rb +++ b/spec/curl_spec.rb @@ -8,7 +8,7 @@ describe Faraday::Curl::Middleware do - let(:version) { "-H 'User-Agent: Faraday v0.9.0'" } + let(:version) { "-H 'User-Agent: Faraday v#{Faraday::VERSION}'" } def create_connection( *request_middlewares ) Faraday.new( :url => 'http://example.com' ) do |b| @@ -49,4 +49,4 @@ def match_command( response, method, *parts ) match_command(response, "PUT", "-H 'Content-Type: application/x-www-form-urlencoded'", "-d 'age=50&name%5B%5D=john&name%5B%5D=doe'", '"http://example.com/echo"') end -end \ No newline at end of file +end From 8224d7d1ea7421ad1029ceb6dd12a41e5a84fc04 Mon Sep 17 00:00:00 2001 From: ne-sachirou Date: Fri, 4 Oct 2019 17:40:48 +0900 Subject: [PATCH 3/4] Escape single quote correctly. --- lib/faraday/curl/middleware.rb | 4 ++-- spec/curl_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/faraday/curl/middleware.rb b/lib/faraday/curl/middleware.rb index 9e3802d..45ab061 100644 --- a/lib/faraday/curl/middleware.rb +++ b/lib/faraday/curl/middleware.rb @@ -42,10 +42,10 @@ def call(env) end def quote(value) - value.gsub("'", "\\'") + value.gsub("'") { "\\'" } end end end end -Faraday::Request.register_middleware :curl => Faraday::Curl::Middleware \ No newline at end of file +Faraday::Request.register_middleware :curl => Faraday::Curl::Middleware diff --git a/spec/curl_spec.rb b/spec/curl_spec.rb index 42812bb..5eb3f59 100644 --- a/spec/curl_spec.rb +++ b/spec/curl_spec.rb @@ -49,4 +49,12 @@ def match_command( response, method, *parts ) match_command(response, "PUT", "-H 'Content-Type: application/x-www-form-urlencoded'", "-d 'age=50&name%5B%5D=john&name%5B%5D=doe'", '"http://example.com/echo"') end + it 'should escape headers' do + connection = create_connection + response = connection.get( "/echo" ) do |request| + request.headers["Cookies"] = "exa'm'ple" + end + match_command(response, "GET", "-H 'Cookies: exa\\'m\\'ple'", '"http://example.com/echo"') + end + end From 7abc30533004783441dd44c888c80b041ffba49d Mon Sep 17 00:00:00 2001 From: ne-sachirou Date: Mon, 7 Oct 2019 11:59:21 +0900 Subject: [PATCH 4/4] `echo 'a'\''b'` works. --- lib/faraday/curl/middleware.rb | 2 +- spec/curl_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/faraday/curl/middleware.rb b/lib/faraday/curl/middleware.rb index 45ab061..74aa964 100644 --- a/lib/faraday/curl/middleware.rb +++ b/lib/faraday/curl/middleware.rb @@ -42,7 +42,7 @@ def call(env) end def quote(value) - value.gsub("'") { "\\'" } + value.gsub("'") { "'\\''" } end end end diff --git a/spec/curl_spec.rb b/spec/curl_spec.rb index 5eb3f59..d1d6765 100644 --- a/spec/curl_spec.rb +++ b/spec/curl_spec.rb @@ -52,9 +52,9 @@ def match_command( response, method, *parts ) it 'should escape headers' do connection = create_connection response = connection.get( "/echo" ) do |request| - request.headers["Cookies"] = "exa'm'ple" + request.headers["Cookies"] = "exa'mple" end - match_command(response, "GET", "-H 'Cookies: exa\\'m\\'ple'", '"http://example.com/echo"') + match_command(response, "GET", "-H 'Cookies: exa'\\''mple'", '"http://example.com/echo"') end end