Skip to content

Commit 8b8f676

Browse files
committed
fix: pass XML_PARSE_UNZIP for SAX file parsing on libxml2 >= 2.14
libxml2 2.15.0 removed the automatic enabling of XML_PARSE_UNZIP in xmlCreateFileParserCtxt, so compressed file parsing silently fails unless the caller explicitly requests decompression. Use xmlCreateURLParserCtxt with XML_PARSE_UNZIP on libxml2 >= 2.14 (when the flag was introduced). On older versions, fall back to xmlCreateFileParserCtxt which auto-decompresses. This also removes the Windows-specific test workaround for the same issue.
1 parent 3b2f7b9 commit 8b8f676

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

ext/nokogiri/xml_sax_parser_context.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ noko_xml_sax_parser_context_s_native_file(VALUE rb_class, VALUE rb_path, VALUE r
116116
rb_raise(rb_eTypeError, "argument must be an Encoding object");
117117
}
118118

119+
#if LIBXML_VERSION >= 21400
120+
xmlParserCtxtPtr c_context = xmlCreateURLParserCtxt(StringValueCStr(rb_path), XML_PARSE_UNZIP);
121+
#else
119122
xmlParserCtxtPtr c_context = xmlCreateFileParserCtxt(StringValueCStr(rb_path));
123+
#endif
120124
if (!c_context) {
121125
rb_raise(rb_eRuntimeError, "failed to create xml sax parser context");
122126
}

test/xml/sax/test_parser.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class TestCase
7777

7878
it "parses a compressed file" do
7979
skip("libxml2 legacy support") unless Nokogiri.uses_libxml? && Nokogiri::LIBXML_ZLIB_ENABLED
80-
skip("TODO: windows libxml 2.15.1 system libraries have ZLIB_ENABLED but it's really not") if Nokogiri::VersionInfo.instance.windows? && Nokogiri::VersionInfo.instance.libxml2_using_system?
8180

8281
filename = XML_FILE + ".gz"
8382
parser.parse_file(filename)

0 commit comments

Comments
 (0)