From 7e9891790de5d3efe2eb0f44433a5c19ab681c20 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 7 Apr 2024 13:30:12 -0400 Subject: [PATCH] add test for how we handle compressed files this is insufficient coverage, there are other methods that likely support decompression. this test is only intended to demonstrate an instance of zlib/lzma support, relative to libxml2's "legacy" option in v2.13.0. --- ext/nokogiri/nokogiri.c | 3 +++ test/files/staff.xml.gz | Bin 0 -> 792 bytes test/xml/sax/test_parser.rb | 10 ++++++++++ 3 files changed, 13 insertions(+) create mode 100644 test/files/staff.xml.gz diff --git a/ext/nokogiri/nokogiri.c b/ext/nokogiri/nokogiri.c index d97413e5c24..66c40bda263 100644 --- a/ext/nokogiri/nokogiri.c +++ b/ext/nokogiri/nokogiri.c @@ -203,6 +203,9 @@ Init_nokogiri(void) rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION)); rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion)); + rb_const_set(mNokogiri, rb_intern("LIBXML_ZLIB_ENABLED"), + xmlHasFeature(XML_WITH_ZLIB) == 1 ? Qtrue : Qfalse); + #ifdef NOKOGIRI_PACKAGED_LIBRARIES rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue); # ifdef NOKOGIRI_PRECOMPILED_LIBRARIES diff --git a/test/files/staff.xml.gz b/test/files/staff.xml.gz new file mode 100644 index 0000000000000000000000000000000000000000..1c634e42ae9cdfff2c878ca189b593007813717e GIT binary patch literal 792 zcmV+z1Lyo7iwFp8F&$J&j0HTQ0%$ zD=j`W#+a2IEf?5rmaS+1`UnN2 z^cP`c5iUnQ%z|M*?DxC__i#8Jgv*%^nPyKcnOfl1ObalMM?AR;A zOf$E&&m&l~Kr{7>nn0P^p7*(S7iPEDqhLTA7dqD4+j(H^p1;QlS}-wufRLJL;>`I} zfiQ=wID@w}kgen<;qZvS<1Au|;~wkCAJaN`RN#+i;j#$#!*CQV^6<}?>lF<0H(K^? z-DDc}!(ckuZ=&3E8Oirrm)|bMD)m+#@))Z97E&K4ww`OVJyX227C(^q^zmw(_W%Udt>tyYc!_BsW4cq1{#) zg#FJXXDnfA>vhjg=v8j37@C=96daZJ9aEN|+bV`;hHyJN#dD&o5T zg3ZF0Cy@IOF3!7Mf>NwCuv_nN|AB*cEeCqVV9vHeCOmTw?{bmvcD%DU(H9sQ=;Q<1 znx7kLj!&piM7YzW4M(P>F7I>gKGqSy_zxBt4L?_8pvr1m(onNUIHEsOtV$PJO~Mh+ z?__zWMW_4ETF~L55OpEU8?sUlGwfU*Huz}z^no~#Qf@bZ4Aqj zhe#$#Y);IFm>+vXH1WJm#!N6OQ_YTJ+jaC9V5gUVL(fE7-fRlj@)g?OAW$!{cs>DL z8n*LQdQPk9xk0goX(WY^s>&HN`h?IVCNPW@c}&)jaPdDaVrX+NEsq#j$PF3Vd`YU> z_w1`|bnDDQokwzS33U}41DUQjnwoR5#)upfXS#-tT1(WD@mqs9=WWNFTs)4NIr@{r W3-7?6*Mn~rC;2bR$*dO#2mk=ZUw@ha literal 0 HcmV?d00001 diff --git a/test/xml/sax/test_parser.rb b/test/xml/sax/test_parser.rb index 832ab05e2ed..062e251d159 100644 --- a/test/xml/sax/test_parser.rb +++ b/test/xml/sax/test_parser.rb @@ -274,6 +274,16 @@ def call_parse_io_with_encoding(encoding) end end + it "parses a compressed file" do + skip("libxml2 legacy support") unless Nokogiri.uses_libxml? && Nokogiri::LIBXML_ZLIB_ENABLED + + filename = XML_FILE + ".gz" + parser.parse_file(filename) + + refute_nil(parser.document.start_elements) + assert_operator(parser.document.start_elements.count, :>, 30) + end + it :test_render_parse_nil_param do assert_raises(TypeError) { parser.parse_memory(nil) } end