From 46482f1869352d240bd9809c86bff6057c316d9d Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 29 Dec 2023 10:35:16 -0500 Subject: [PATCH] test: accept "UTF-8" as an encoding alias for "UTF8" As of libxml 2.12.0, the `page.encoding` value inspected by this test is dependent on how libiconv is built (specifically: which aliases are supported). - if alias "UTF8" is defined, then the page encoding will be "UTF-8" - if alias "UTF8" is not defined, then the page encoding will be "UTF8" The modified test started failing on Windows and MacOS (where Nokogiri compiles libiconv and statically links it into the native (precompiled) gem) but still passed on Linux (where libc dynamically provides libiconv symbols). --- test/test_mechanize_http_agent.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/test_mechanize_http_agent.rb b/test/test_mechanize_http_agent.rb index f6beb06d..f2fea1e7 100644 --- a/test/test_mechanize_http_agent.rb +++ b/test/test_mechanize_http_agent.rb @@ -1309,8 +1309,13 @@ def test_response_parse_content_type_encoding_broken_utf_8 page = @agent.response_parse @res, body, @uri assert_instance_of Mechanize::Page, page - assert_equal 'UTF8', page.encoding - assert_equal 'UTF8', page.parser.encoding + + # as of libxml 2.12.0, the result is dependent on how libiconv is built (which aliases are supported) + # if the alias "UTF8" is defined, then the result will be "UTF-8". + # if the alias "UTF8" is not defined, then the result will be "UTF8". + # note that this alias may be defined by Nokogiri itself in its EncodingHandler class. + assert_includes ["UTF8", "UTF-8"], page.encoding + assert_includes ["UTF8", "UTF-8"], page.parser.encoding end def test_response_parse_content_type_encoding_garbage