From 762df0c71705d1c054aca4abd95a638774a47242 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 7 Jun 2023 10:30:37 -0400 Subject: [PATCH] test: work around libxml2 encoding changes versions 2.11.0..2.11.4 do not recover from encoding errors. upcoming release will change the encoding of the resulting doc as a result of recovery changes in libxml2. See https://gitlab.gnome.org/GNOME/libxml2/-/issues/543 for more context. --- test/test_mechanize_page_link.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/test_mechanize_page_link.rb b/test/test_mechanize_page_link.rb index 5e77dcc0..988328cc 100644 --- a/test/test_mechanize_page_link.rb +++ b/test/test_mechanize_page_link.rb @@ -1,5 +1,7 @@ # coding: utf-8 +puts "Nokogiri::VERSION_INFO: #{Nokogiri::VERSION_INFO}" + require 'mechanize/test_case' class TestMechanizePageLink < Mechanize::TestCase @@ -111,11 +113,15 @@ def test_encoding_charset_after_title def test_encoding_charset_after_title_bad skip_if_nkf_dependency + # https://gitlab.gnome.org/GNOME/libxml2/-/issues/543 + skip if Nokogiri.uses_libxml?([">= 2.11.0", "<= 2.11.4"]) + expected_encoding = Nokogiri.uses_libxml?("< 2.11.0") ? 'UTF-8' : 'Shift_JIS' + page = util_page UTF8 assert_equal false, page.encoding_error? - assert_equal 'UTF-8', page.encoding + assert_equal expected_encoding, page.encoding end def test_encoding_charset_after_title_double_bad @@ -131,6 +137,10 @@ def test_encoding_charset_after_title_double_bad def test_encoding_charset_bad skip_if_nkf_dependency + # https://gitlab.gnome.org/GNOME/libxml2/-/issues/543 + skip if Nokogiri.uses_libxml?([">= 2.11.0", "<= 2.11.4"]) + expected_encoding = Nokogiri.uses_libxml?("< 2.11.0") ? 'UTF-8' : 'Shift_JIS' + page = util_page "#{UTF8_TITLE}" page.encodings.replace %w[ UTF-8 @@ -139,7 +149,7 @@ def test_encoding_charset_bad assert_equal false, page.encoding_error? - assert_equal 'UTF-8', page.encoding + assert_equal expected_encoding, page.encoding end def test_encoding_meta_charset