From 973b813a4ddcfa0cf184909b6f2a4677b4e714b9 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 18 Jun 2021 16:11:48 -0400 Subject: [PATCH] handle libxslt built without date-time functionality - expose this compile-time config as Nokogiri::VERSION_INFO["libxslt"]["datetime_enabled"] - skip the assertion that depends on this behavior --- CHANGELOG.md | 4 ++++ ext/nokogiri/nokogiri.c | 7 +++++++ ext/nokogiri/xslt_stylesheet.c | 1 - lib/nokogiri/version/info.rb | 5 +++++ test/test_version.rb | 1 + test/test_xslt_transforms.rb | 10 ++++++---- 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a10d2206f..9da2d45795 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ Please also note that the `Nokogiri::HTML` parse methods still use libxml2's HTM Many thanks to Sam Ruby, Steve Checkoway, and Craig Barnes for creating and maintaining Nokogumbo and supporting the Gumbo HTML5 parser. They're now Nokogiri core contributors with all the powers and privileges pertaining thereto. 🙌 +#### Other + +* [CRuby] `Nokogiri::VERSION_INFO["libxslt"]["datetime_enabled"]` is a new boolean value which describes whether libxslt (or, more properly, libexslt) has compiled-in datetime support. This generally going to be `true`, but some distros ship without this support (e.g., some mingw UCRT-based packages, see https://github.com/msys2/MINGW-packages/pull/8957). See [#2272](https://github.com/sparklemotion/nokogiri/issues/2272) for more details. + ### Changed diff --git a/ext/nokogiri/nokogiri.c b/ext/nokogiri/nokogiri.c index 1fe83031d0..f16f84267d 100644 --- a/ext/nokogiri/nokogiri.c +++ b/ext/nokogiri/nokogiri.c @@ -218,6 +218,13 @@ Init_nokogiri() #endif xmlInitParser(); + exsltRegisterAll(); + + if (xsltExtModuleFunctionLookup((xmlChar*)"date-time", EXSLT_DATE_NAMESPACE)) { + rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qtrue); + } else { + rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qfalse); + } cNokogiriSyntaxError = rb_define_class_under(mNokogiri, "SyntaxError", rb_eStandardError); noko_init_xml_syntax_error(); diff --git a/ext/nokogiri/xslt_stylesheet.c b/ext/nokogiri/xslt_stylesheet.c index fd27e94004..02247a3e34 100644 --- a/ext/nokogiri/xslt_stylesheet.c +++ b/ext/nokogiri/xslt_stylesheet.c @@ -64,7 +64,6 @@ parse_stylesheet_doc(VALUE klass, VALUE xmldocobj) VALUE errstr, exception; xsltStylesheetPtr ss ; Data_Get_Struct(xmldocobj, xmlDoc, xml); - exsltRegisterAll(); errstr = rb_str_new(0, 0); xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler); diff --git a/lib/nokogiri/version/info.rb b/lib/nokogiri/version/info.rb index f6a9092b91..309490defc 100644 --- a/lib/nokogiri/version/info.rb +++ b/lib/nokogiri/version/info.rb @@ -52,6 +52,10 @@ def libxml2_has_iconv? defined?(Nokogiri::LIBXML_ICONV_ENABLED) && Nokogiri::LIBXML_ICONV_ENABLED end + def libxslt_has_datetime? + defined?(Nokogiri::LIBXSLT_DATETIME_ENABLED) && Nokogiri::LIBXSLT_DATETIME_ENABLED + end + def libxml2_using_packaged? libxml2? && Nokogiri::PACKAGED_LIBRARIES end @@ -151,6 +155,7 @@ def to_hash else libxslt["source"] = "system" end + libxslt["datetime_enabled"] = libxslt_has_datetime? libxslt["compiled"] = compiled_libxslt_version.to_s libxslt["loaded"] = loaded_libxslt_version.to_s end diff --git a/test/test_version.rb b/test/test_version.rb index dda8f392ba..e8f7468b6f 100644 --- a/test/test_version.rb +++ b/test/test_version.rb @@ -59,6 +59,7 @@ def test_version_info_for_libxml assert_equal("#{major}.#{minor}.#{bug}", Nokogiri::VERSION_INFO["libxml"]["loaded"]) assert(version_info["libxml"].key?("iconv_enabled")) + assert(version_info["libxslt"].key?("datetime_enabled")) end def test_version_info_for_libxslt diff --git a/test/test_xslt_transforms.rb b/test/test_xslt_transforms.rb index 175c9920e3..1f34290b6a 100644 --- a/test/test_xslt_transforms.rb +++ b/test/test_xslt_transforms.rb @@ -218,10 +218,12 @@ def test_exslt assert_equal("func-result", result_doc.at("/root/function").content) assert_equal(3, result_doc.at("/root/max").content.to_i) - assert_match( - /\d{4}-\d\d-\d\d([-|+]\d\d:\d\d)?/, - result_doc.at("/root/date").content - ) + if Nokogiri::VersionInfo.instance.libxslt_has_datetime? + assert_match( + /\d{4}-\d\d-\d\d([-|+]\d\d:\d\d)?/, + result_doc.at("/root/date").content + ) + end result_doc.xpath("/root/params/*").each do |p| assert_equal(p.content, params[p.name.intern]) end