Skip to content

Commit

Permalink
handle libxslt built without date-time functionality
Browse files Browse the repository at this point in the history
- expose this compile-time config as Nokogiri::VERSION_INFO["libxslt"]["datetime_enabled"]
- skip the assertion that depends on this behavior
  • Loading branch information
flavorjones committed Jun 19, 2021
1 parent 899c319 commit 5bb0bcb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions ext/nokogiri/nokogiri.c
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion ext/nokogiri/xslt_stylesheet.c
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions lib/nokogiri/version/info.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/test_version.rb
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions test/test_xslt_transforms.rb
Expand Up @@ -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
Expand Down

0 comments on commit 5bb0bcb

Please sign in to comment.