From a5e2e6238ba9e25a9b7dc84a18d79d1cce1c07a5 Mon Sep 17 00:00:00 2001 From: Les Nightingill Date: Tue, 6 Jun 2017 18:42:54 -0700 Subject: [PATCH 1/4] add test in test/shared_test.rb to reproduce string concatenation issue --- .gitignore | 1 + lib/webmock/request_registry.rb | 2 ++ test/dumpfile.pg_dump | Bin 0 -> 11848 bytes test/shared_test.rb | 12 ++++++++++++ webmock.gemspec | 1 + 5 files changed, 16 insertions(+) create mode 100644 test/dumpfile.pg_dump diff --git a/.gitignore b/.gitignore index 8611c37e4..cc587f155 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ tmp/* *.rbx .ruby-gemset .ruby-version +.byebug_history diff --git a/lib/webmock/request_registry.rb b/lib/webmock/request_registry.rb index d02c9b322..13610a011 100644 --- a/lib/webmock/request_registry.rb +++ b/lib/webmock/request_registry.rb @@ -1,3 +1,5 @@ +require 'active_support' + module WebMock class RequestRegistry diff --git a/test/dumpfile.pg_dump b/test/dumpfile.pg_dump new file mode 100644 index 0000000000000000000000000000000000000000..1e602fe6883cecee6f22be68458367fbf8884e37 GIT binary patch literal 11848 zcmcgyTZ|i58J^uHG~Fh>geJX+!V$OK74BkteeDvpj(3u}@vXME$v(g^v1c7OzST1u z8iZ7MKm`?4Rq%*ZLEDEu&>IC_DjF`UB1Dl|B>GAV;;9dPt9U@-KmR%78P7Rq)>&^d zQcmnSxBvhC`|quuUN2SW4r>Pv&CShe@Z3X(d+BhL4xggKK{{;H0hb(s4{gga&YR7P zhGW?duF9??R$_7g$7Q$c;`dRo_*BhkS?O1)s zu=>qGtJ80j6J&9taVoR8wm?^DNU=BIJ0y0??AjJi+`wMKc&n5UdQiQwUT@TZlDZc7 zio`6@B|wbrnEjSHY8lNze`_%60YQfCjNm_;5;o}XiLBekWF3HeV)0ZQ@kk}J*;slt zrioxvxYl!x+{s*B*O0;|;Z44#=NdY3C&+|=$k{^UA=1!G)goPVf;d)h*fkw1N?a+7 zu_eX4k*^f_!bP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+ku}B!Djc+5nfzYmepv^%A#$uym_!*Iel zp#ocBN^uI`7WI6C497o+tk~9c?mI$a5#o%tE$Y4L!+h)>bRyU#JD}8wOh}6?T=JN$ zpxR5?Nn{C{WD)3%K^N@WseX!ybJZ2+%?dVUji+$tz6|K2T6=MVEb*Sp%xak7CR=ss zKB%Bu+C&N`JTDRsy(DT>oce1g4c2m)@3~yvB{eQZ%Rz2WS>UFwtL({>jr&`{;{KUX zu-9;-T1JXSL%5)>xPo$>o!g*b((-i`BE)MZfb@6|Awt~Nfl8tg;;-+$Q-WnZ%qR`OLbXW>IXGBB%y*MOS~eSSv(o`L-zdNT=6U@x$qZs;e>z2C7jiDTZ6&ubjF$M{|fDH z(C6u3a-8z=yG%TafBBPAf4h!vkZr# z&z@&OkxpR8+aDH{nq7zU1b}@zWw`pLC2%tRr5UhruB3Jjf*3q|2JBQnfjk?ET}nF! zqziFE3EW<<5lh)7PkgfZ%K9(f{OEUo{b;WE@jbWln=xaN-~4}3`oxC- literal 0 HcmV?d00001 diff --git a/test/shared_test.rb b/test/shared_test.rb index 48b60f81d..32d38c35b 100644 --- a/test/shared_test.rb +++ b/test/shared_test.rb @@ -1,3 +1,4 @@ +require 'active_support' require File.expand_path(File.dirname(__FILE__) + '/http_request') module SharedTest @@ -62,6 +63,17 @@ def test_verification_that_expected_request_occured_with_body_and_headers body: "abc", headers: {'A' => 'a'}) end + def test_verification_that_expected_request_occured_with_utf8_body_and_headers + body1 = File.read(File.expand_path('test/dumpfile.pg_dump')) + http_request(:post, "http://www.example.com/", + body: body1, headers: {'A' => 'a'}) + body2 = ActiveSupport::Gzip.compress("").force_encoding('ASCII-8BIT') + http_request(:post, "http://www.example.com/", + body: body2, headers: {'A' => 'a'}) + assert_requested(:post, "http://www.example.com", + body: body1, headers: {'A' => 'b'}) + end + def test_verification_that_expected_request_occured_with_query_params stub_request(:any, "http://www.example.com").with(query: hash_including({"a" => ["b", "c"]})) http_request(:get, "http://www.example.com/?a[]=b&a[]=c&x=1") diff --git a/webmock.gemspec b/webmock.gemspec index 494ddf7f0..99ba79f2b 100644 --- a/webmock.gemspec +++ b/webmock.gemspec @@ -38,6 +38,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'minitest', '>= 5.0.0' s.add_development_dependency 'test-unit', '>= 3.0.0' s.add_development_dependency 'rdoc', '> 3.5.0' + s.add_development_dependency 'activesupport' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") From dd0a735dc6c3d319f14e4070d66885440353cf80 Mon Sep 17 00:00:00 2001 From: Les Nightingill Date: Sat, 24 Jun 2017 11:50:08 -0700 Subject: [PATCH 2/4] fixes the utf-encoding error message that is displayed in place of legitimate test fail message --- lib/webmock/request_registry.rb | 4 +--- test/shared_test.rb | 18 +++++++++++------- test/{dumpfile.pg_dump => support/body1} | Bin test/support/body2 | Bin 0 -> 20 bytes webmock.gemspec | 1 - 5 files changed, 12 insertions(+), 11 deletions(-) rename test/{dumpfile.pg_dump => support/body1} (100%) create mode 100644 test/support/body2 diff --git a/lib/webmock/request_registry.rb b/lib/webmock/request_registry.rb index 13610a011..cae6ce9d4 100644 --- a/lib/webmock/request_registry.rb +++ b/lib/webmock/request_registry.rb @@ -1,5 +1,3 @@ -require 'active_support' - module WebMock class RequestRegistry @@ -27,7 +25,7 @@ def to_s else text = "" self.requested_signatures.each do |request_signature, times_executed| - text << "#{request_signature} was made #{times_executed} time#{times_executed == 1 ? '' : 's' }\n" + text.force_encoding('ASCII-8BIT') << "#{request_signature} was made #{times_executed} time#{times_executed == 1 ? '' : 's' }\n" end text end diff --git a/test/shared_test.rb b/test/shared_test.rb index 32d38c35b..42b6514e2 100644 --- a/test/shared_test.rb +++ b/test/shared_test.rb @@ -1,4 +1,3 @@ -require 'active_support' require File.expand_path(File.dirname(__FILE__) + '/http_request') module SharedTest @@ -8,6 +7,8 @@ def setup super @stub_http = stub_http_request(:any, "http://www.example.com") @stub_https = stub_http_request(:any, "https://www.example.com") + @body1 = File.read(File.expand_path('test/support/body1')) + @body2 = File.read(File.expand_path('test/support/body2')).force_encoding('ASCII-8BIT') end def test_assert_requested_with_stub_and_block_raises_error @@ -64,14 +65,17 @@ def test_verification_that_expected_request_occured_with_body_and_headers end def test_verification_that_expected_request_occured_with_utf8_body_and_headers - body1 = File.read(File.expand_path('test/dumpfile.pg_dump')) http_request(:post, "http://www.example.com/", - body: body1, headers: {'A' => 'a'}) - body2 = ActiveSupport::Gzip.compress("").force_encoding('ASCII-8BIT') + body: @body1, headers: {'A' => 'a'}) http_request(:post, "http://www.example.com/", - body: body2, headers: {'A' => 'a'}) - assert_requested(:post, "http://www.example.com", - body: body1, headers: {'A' => 'b'}) + body: @body2, headers: {'A' => 'a'}) + assert_fail(/.*/) do + # we know this will fail, but it shouldn't cause an exception + assert_requested(:post, "http://www.example.com", + body: @body1, headers: {'A' => 'b'}) + end + rescue Encoding::CompatibilityError => e + flunk e.message end def test_verification_that_expected_request_occured_with_query_params diff --git a/test/dumpfile.pg_dump b/test/support/body1 similarity index 100% rename from test/dumpfile.pg_dump rename to test/support/body1 diff --git a/test/support/body2 b/test/support/body2 new file mode 100644 index 0000000000000000000000000000000000000000..ee04295d3f2f59a84b2540652d92a6c61253b0d1 GIT binary patch literal 20 Ucmb2|=3tnnP8nVA6w04e1Hq5uE@ literal 0 HcmV?d00001 diff --git a/webmock.gemspec b/webmock.gemspec index 99ba79f2b..494ddf7f0 100644 --- a/webmock.gemspec +++ b/webmock.gemspec @@ -38,7 +38,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'minitest', '>= 5.0.0' s.add_development_dependency 'test-unit', '>= 3.0.0' s.add_development_dependency 'rdoc', '> 3.5.0' - s.add_development_dependency 'activesupport' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") From 5f46df7d8baca178826c17768e0632e2c03ac0af Mon Sep 17 00:00:00 2001 From: Les Nightingill Date: Sat, 24 Jun 2017 11:50:08 -0700 Subject: [PATCH 3/4] fixes the utf-encoding error message that is displayed in place of legitimate test fail message --- .gitignore | 1 - lib/webmock/request_registry.rb | 4 +--- test/shared_test.rb | 18 +++++++++++------- test/{dumpfile.pg_dump => support/body1} | Bin test/support/body2 | Bin 0 -> 20 bytes webmock.gemspec | 1 - 6 files changed, 12 insertions(+), 12 deletions(-) rename test/{dumpfile.pg_dump => support/body1} (100%) create mode 100644 test/support/body2 diff --git a/.gitignore b/.gitignore index cc587f155..8611c37e4 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,3 @@ tmp/* *.rbx .ruby-gemset .ruby-version -.byebug_history diff --git a/lib/webmock/request_registry.rb b/lib/webmock/request_registry.rb index 13610a011..cae6ce9d4 100644 --- a/lib/webmock/request_registry.rb +++ b/lib/webmock/request_registry.rb @@ -1,5 +1,3 @@ -require 'active_support' - module WebMock class RequestRegistry @@ -27,7 +25,7 @@ def to_s else text = "" self.requested_signatures.each do |request_signature, times_executed| - text << "#{request_signature} was made #{times_executed} time#{times_executed == 1 ? '' : 's' }\n" + text.force_encoding('ASCII-8BIT') << "#{request_signature} was made #{times_executed} time#{times_executed == 1 ? '' : 's' }\n" end text end diff --git a/test/shared_test.rb b/test/shared_test.rb index 32d38c35b..42b6514e2 100644 --- a/test/shared_test.rb +++ b/test/shared_test.rb @@ -1,4 +1,3 @@ -require 'active_support' require File.expand_path(File.dirname(__FILE__) + '/http_request') module SharedTest @@ -8,6 +7,8 @@ def setup super @stub_http = stub_http_request(:any, "http://www.example.com") @stub_https = stub_http_request(:any, "https://www.example.com") + @body1 = File.read(File.expand_path('test/support/body1')) + @body2 = File.read(File.expand_path('test/support/body2')).force_encoding('ASCII-8BIT') end def test_assert_requested_with_stub_and_block_raises_error @@ -64,14 +65,17 @@ def test_verification_that_expected_request_occured_with_body_and_headers end def test_verification_that_expected_request_occured_with_utf8_body_and_headers - body1 = File.read(File.expand_path('test/dumpfile.pg_dump')) http_request(:post, "http://www.example.com/", - body: body1, headers: {'A' => 'a'}) - body2 = ActiveSupport::Gzip.compress("").force_encoding('ASCII-8BIT') + body: @body1, headers: {'A' => 'a'}) http_request(:post, "http://www.example.com/", - body: body2, headers: {'A' => 'a'}) - assert_requested(:post, "http://www.example.com", - body: body1, headers: {'A' => 'b'}) + body: @body2, headers: {'A' => 'a'}) + assert_fail(/.*/) do + # we know this will fail, but it shouldn't cause an exception + assert_requested(:post, "http://www.example.com", + body: @body1, headers: {'A' => 'b'}) + end + rescue Encoding::CompatibilityError => e + flunk e.message end def test_verification_that_expected_request_occured_with_query_params diff --git a/test/dumpfile.pg_dump b/test/support/body1 similarity index 100% rename from test/dumpfile.pg_dump rename to test/support/body1 diff --git a/test/support/body2 b/test/support/body2 new file mode 100644 index 0000000000000000000000000000000000000000..ee04295d3f2f59a84b2540652d92a6c61253b0d1 GIT binary patch literal 20 Ucmb2|=3tnnP8nVA6w04e1Hq5uE@ literal 0 HcmV?d00001 diff --git a/webmock.gemspec b/webmock.gemspec index 99ba79f2b..494ddf7f0 100644 --- a/webmock.gemspec +++ b/webmock.gemspec @@ -38,7 +38,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'minitest', '>= 5.0.0' s.add_development_dependency 'test-unit', '>= 3.0.0' s.add_development_dependency 'rdoc', '> 3.5.0' - s.add_development_dependency 'activesupport' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") From edfdf64e977867667697d6bb95263f9f31ba61b9 Mon Sep 17 00:00:00 2001 From: Les Nightingill Date: Sun, 25 Jun 2017 12:55:15 -0700 Subject: [PATCH 4/4] fixes test bug preventing Travis CI builds from passing --- spec/quality_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index d4cab112b..a916b86b9 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -30,7 +30,7 @@ def check_for_tab_characters(filename) failing_lines = [] File.readlines(filename).each_with_index do |line,number| - failing_lines << number + 1 if line =~ /\t/ + failing_lines << number + 1 if line.force_encoding('UTF-8') =~ /\t/ end unless failing_lines.empty? @@ -41,7 +41,8 @@ def check_for_tab_characters(filename) def check_for_extra_spaces(filename) failing_lines = [] File.readlines(filename).each_with_index do |line,number| - next if line =~ /^\s+#.*\s+\n$/ + line.force_encoding('UTF-8') =~ /^\s+#.*\s+\n$/ + next if line.force_encoding('UTF-8') =~ /^\s+#.*\s+\n$/ failing_lines << number + 1 if line =~ /\s+\n$/ end @@ -64,7 +65,7 @@ def check_for_extra_spaces(filename) error_messages = [] Dir.chdir(File.expand_path("../..", __FILE__)) do `git ls-files`.split("\n").each do |filename| - next if filename =~ /\.gitmodules|fixtures/ + next if filename =~ /\.gitmodules|fixtures|support/ error_messages << check_for_tab_characters(filename) error_messages << check_for_extra_spaces(filename) end