From 6b1ae646f77a9a3fa5c280f2de97fb38766e3db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= Date: Thu, 7 Nov 2019 14:29:02 -0500 Subject: [PATCH 1/3] parsers/base: make sure content always ends with an empty line For some whois output where the content does not end with an empty new line, the whois call was returning an 'Unexpected token: % (c) 2019 Canadian Internet Registration Authority, (http://www.cira.ca/)' error, for instance. This fixes that by forcing into existence that ending new line. --- lib/whois/parsers/base.rb | 2 +- spec/whois/parsers/base_spec.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/whois/parsers/base.rb b/lib/whois/parsers/base.rb index 9acbae4f..b35ef2c9 100644 --- a/lib/whois/parsers/base.rb +++ b/lib/whois/parsers/base.rb @@ -363,7 +363,7 @@ def response_unavailable? protected def content_for_scanner - @content_for_scanner ||= content.to_s.gsub(/\r\n/, "\n") + @content_for_scanner ||= "#{content.to_s.gsub(/\r\n/, "\n").delete_suffix("\n")}\n" end def cached_properties_fetch(key) diff --git a/spec/whois/parsers/base_spec.rb b/spec/whois/parsers/base_spec.rb index 97bbfb86..1c23ba1d 100644 --- a/spec/whois/parsers/base_spec.rb +++ b/spec/whois/parsers/base_spec.rb @@ -71,16 +71,21 @@ end describe "#content_for_scanner" do + it "returns the part body with line feed normalized" do + instance = described_class.new(Whois::Record::Part.new(:body => "This is\r\nthe response.\r\n", :host => "whois.example.test")) + expect(instance.send(:content_for_scanner)).to eq("This is\nthe response.\n") + end + it "returns the part body with line feed normalized" do instance = described_class.new(Whois::Record::Part.new(:body => "This is\r\nthe response.", :host => "whois.example.test")) - expect(instance.send(:content_for_scanner)).to eq("This is\nthe response.") + expect(instance.send(:content_for_scanner)).to eq("This is\nthe response.\n") end it "caches the result" do instance = described_class.new(Whois::Record::Part.new(:body => "This is\r\nthe response.", :host => "whois.example.test")) expect(instance.instance_eval { @content_for_scanner }).to be_nil instance.send(:content_for_scanner) - expect(instance.instance_eval { @content_for_scanner }).to eq("This is\nthe response.") + expect(instance.instance_eval { @content_for_scanner }).to eq("This is\nthe response.\n") end end From 6482ff4c3bf328f6c39cb47451c4a0fa22c7ebab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= Date: Fri, 21 Feb 2020 16:23:37 -0500 Subject: [PATCH 2/3] fixup! 6b1ae646f77a9a3fa5c280f2de97fb38766e3db7 --- lib/whois/parsers/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/whois/parsers/base.rb b/lib/whois/parsers/base.rb index b35ef2c9..a4c8873c 100644 --- a/lib/whois/parsers/base.rb +++ b/lib/whois/parsers/base.rb @@ -363,7 +363,7 @@ def response_unavailable? protected def content_for_scanner - @content_for_scanner ||= "#{content.to_s.gsub(/\r\n/, "\n").delete_suffix("\n")}\n" + @content_for_scanner ||= "#{content.to_s.gsub(/\r\n/, "\n").gsub("\n$", '')}\n" end def cached_properties_fetch(key) From 859642d23d2de91a482f09a3e63869312c7af4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= Date: Fri, 21 Feb 2020 16:33:31 -0500 Subject: [PATCH 3/3] fixup! 6b1ae646f77a9a3fa5c280f2de97fb38766e3db7 --- lib/whois/parsers/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/whois/parsers/base.rb b/lib/whois/parsers/base.rb index a4c8873c..9997d6c6 100644 --- a/lib/whois/parsers/base.rb +++ b/lib/whois/parsers/base.rb @@ -363,7 +363,7 @@ def response_unavailable? protected def content_for_scanner - @content_for_scanner ||= "#{content.to_s.gsub(/\r\n/, "\n").gsub("\n$", '')}\n" + @content_for_scanner ||= "#{content.to_s.gsub(/\r\n/, "\n").gsub(/\n$/, '')}\n" end def cached_properties_fetch(key)