[ruby-talk:444220] [ANN] nokogiri v1.15.0 released

Nokogiri v1.15.0 has been released!

This is primarily a feature release, with some small bugfixes.

Full release notes are at
Release 1.15.0 / 2023-05-15 · sparklemotion/nokogiri · GitHub but they are
included below for your convenience.

···

---

Nokogiri (鋸) makes it easy and painless to work with XML and HTML from
Ruby. It provides a sensible, easy-to-understand API for reading, writing,
modifying, and querying documents. It is fast and standards-compliant by
relying on native parsers like libxml2, libgumbo, or xerces.

---

## 1.15.0 / 2023-05-15

### Notes

#### Ability to opt into system `malloc` and `free`

Since 2009, Nokogiri has configured libxml2 to use `ruby_xmalloc` et al for
memory management. This has provided benefits for memory management, but
comes with a performance penalty.

Users can now opt into using system `malloc` for libxml2 memory management
by setting an environment variable:

# "default" here means "libxml2's default" which is system malloc
NOKOGIRI_LIBXML_MEMORY_MANAGEMENT=default

Benchmarks show that this setting will significantly improve performance,
but be aware that the tradeoff may involve poorer memory management
including bloated heap sizes and/or OOM conditions.

You can read more about this in the decision record at
[`adr/2023-04-libxml-memory-management.md`](adr/2023-04-libxml-memory-management.md).

### Dependencies

* [CRuby] Vendored libxml2 is updated to v2.11.3 from v2.10.4. For details
please see:
  * libxml2 2.11.0 · GNOME / libxml2 · GitLab
  * libxml2 2.11.1 · GNOME / libxml2 · GitLab
  * libxml2 2.11.2 · GNOME / libxml2 · GitLab
  * libxml2 2.11.3 · GNOME / libxml2 · GitLab
* [CRuby] Vendored libxslt is updated to v1.1.38 from v1.1.37. For details
please see:
  * libxslt 1.1.38 · GNOME / libxslt · GitLab

### Added

* `Encoding` objects may now be passed to serialization methods like
`#to_xml`, `#to_html`, `#serialize`, and `#write_to` to specify the output
encoding. Previously only encoding names (strings) were accepted. [[#2774](
[feature] `Node#write_to` and friends should accept `Encoding` objects for `:encoding` kwargs · Issue #2774 · sparklemotion/nokogiri · GitHub), [#2798](
fix: support Encoding class for xml write_to by ellaklara · Pull Request #2798 · sparklemotion/nokogiri · GitHub)] (Thanks,
[@ellaklara](ellaklara (Ella Klara Westerlund) · GitHub)!)
* [CRuby] Users may opt into using system `malloc` for libxml2 memory
management. For more detail, see note above or
[`adr/2023-04-libxml-memory-management.md`](adr/2023-04-libxml-memory-management.md).

### Changed

* [CRuby] `Schema.from_document` now makes a defensive copy of the document
if it has blank text nodes with Ruby objects instantiated for them. This
prevents unsafe behavior in libxml2 from causing a segfault. There is a
small performance cost, but we think this has the virtue of being "what the
user meant" since modifying the original is surprising behavior for most
users. Previously this was addressed in v1.10.9 by raising an exception.

### Fixed

* [CRuby] `XSLT.transform` now makes a defensive copy of the document if it
has blank text nodes with Ruby objects instantiated for them _and_ the
template uses `xsl:strip-spaces`. This prevents unsafe behavior in libxslt
from causing a segfault. There is a small performance cost, but we think
this has the virtue of being "what the user meant" since modifying the
original is surprising behavior for most users. Previously this would allow
unsafe memory access and potentially segfault. [[#2800](
XSLT segfault · Issue #2800 · sparklemotion/nokogiri · GitHub)]

### Improved

* `Nokogiri::XML::Node::SaveOptions#inspect` now shows the names of the
options set in the bitmask, similar to `ParseOptions`. [[#2767](
[feature] SaveOptions.inspect should show the options set (similar to ParseOptions) · Issue #2767 · sparklemotion/nokogiri · GitHub)]
* `#inspect` and pretty-printing are improved for `AttributeDecl`,
`ElementContent`, `ElementDecl`, and `EntityDecl`.
* [CRuby] The C extension now uses Ruby's [TypedData API](
extension - RDoc Documentation)
for managing all the libxml2 structs. Write barriers may improve GC
performance in some extreme cases. [[#2808](
epic: update C extension to use the `TypedData` API · Issue #2808 · sparklemotion/nokogiri · GitHub)] (Thanks,
[@etiennebarrie](etiennebarrie (Étienne Barrié) · GitHub) and [@byroot](
byroot (Jean Boussier) · GitHub)!)
* [CRuby] `ObjectSpace.memsize_of` reports a pretty good guess of memory
usage when called on `Nokogiri::XML::Document` objects. [[#2807](
Migrate Nokogiri::XML::Document to the TypedData API by etiennebarrie · Pull Request #2807 · sparklemotion/nokogiri · GitHub)] (Thanks,
[@etiennebarrie](etiennebarrie (Étienne Barrié) · GitHub) and [@byroot](
byroot (Jean Boussier) · GitHub)!)
* [CRuby] Users installing the "ruby" platform gem and compiling libxml2
and libxslt from source will now be using a modern `config.guess` and
`config.sub` that supports new architectures like `loongarch64`. [[#2831](
fix build error for nokogiri in loongarch64 by zhangwenlong8911 · Pull Request #2831 · sparklemotion/nokogiri · GitHub)] (Thanks,
[@zhangwenlong8911](zhangwenlong8911 (zhangwenlong) · GitHub)!)
* [CRuby] HTML5 parser:
  * adjusts the specified attributes, adding `xlink:arcrole` and removing
`xml:base` [[#2841]([upstream] html5lib-tests head has failing tests · Issue #2841 · sparklemotion/nokogiri · GitHub),
[#2842](gumbo: update adjusted foreign attributes by flavorjones · Pull Request #2842 · sparklemotion/nokogiri · GitHub)]
  * allows `<hr>` in `<select>` [[whatwg/html#3410](
Proposal: Allow adding separator rows to <select> boxes using <hr> · Issue #3410 · whatwg/html · GitHub), [whatwg/html#9124](
Allow <hr> to be used inside <select> as a separator by annevk · Pull Request #9124 · whatwg/html · GitHub)]
* [JRuby] `Node#first_element_child` now returns `nil` if there are only
non-element children. Previously a null pointer exception was raised.
[[#2808](epic: update C extension to use the `TypedData` API · Issue #2808 · sparklemotion/nokogiri · GitHub), [#2844](
fix(jruby): first_element_child properly returns nil by flavorjones · Pull Request #2844 · sparklemotion/nokogiri · GitHub)]
* Documentation for `Nokogiri::XSLT` now has usage examples including
custom function handlers.

### Deprecated

* Passing a `Nokogiri::XML::Node` as the first parameter to `CDATA.new` is
deprecated and will generate a warning. This parameter should be a kind of
`Nokogiri::XML::Document`. This will become an error in a future version of
Nokogiri.
* Passing a `Nokogiri::XML::Node` as the first parameter to
`Schema.from_document` is deprecated and will generate a warning. This
parameter should be a kind of `Nokogiri::XML::Document`. This will become
an error in a future version of Nokogiri.
* Passing a `Nokogiri::XML::Node` as the second parameter to `Text.new` is
deprecated and will generate a warning. This parameter should be a kind of
`Nokogiri::XML::Document`. This will become an error in a future version of
Nokogiri.
* [CRuby] Calling a custom XPath function without the `nokogiri` namespace
is deprecated and will generate a warning. Support for non-namespaced
functions will be removed in a future version of Nokogiri. (Note that JRuby
has never supported non-namespaced custom XPath functions.)

### Thank you!

The following people and organizations were kind enough to sponsor
@flavorjones or the Nokogiri project during the development of v1.15.0:

* Götz Görisch (@GoetzGoerisch)
* Airbnb (@airbnb)
* Kyohei Nanba (@kyo-nanba)
* Maxime Gauthier (@biximilien)
* @renuo
* @dbootyfvrt
* YOSHIDA Katsuhiko (@kyoshidajp)
* Homebrew (@Homebrew)
* Hiroshi SHIBATA (@hsbt)
* PuLLi (@the-pulli)
* SiteLog GmbH (@sitelog-gmbh)
* @zzak
* Evil Martians (@evilmartians)
* Ajaya Agrawalla (@ajaya)
* Modern Treasury (@Modern-Treasury)
* Danilo Lessa Bernardineli (@danlessa)

We'd also like to thank @github who donate a ton of compute time for our CI
pipelines!

---

sha256 checksums:

7dbb717c6abc6b99baa4a4e1586a6de5332513f72a8b3568a69836268c2e1f86
 nokogiri-1.15.0-aarch64-linux.gem
a60c373d86a9a181f9ace78793c4a91ab8fa971af3cce93e9fdf022cd808fe41
 nokogiri-1.15.0-arm-linux.gem
41d312b2d4aa6b6750c2431a25c1bf25fb567bc1e0a750cf55dd02354967724b
 nokogiri-1.15.0-arm64-darwin.gem
51cc8d4d98473d00c0ee18266d146677161b6dd16f8c89cc637db91d47b87c63
 nokogiri-1.15.0-java.gem
1b2d92e240d12ac0a27cb0618f52af6c405831fd339a45aaab265cecda1dc6ab
 nokogiri-1.15.0-x64-mingw-ucrt.gem
497840b3ed9037095fbdd1bf6f7c63d23efab5bcbb03b89d94a6ac8bcab3eda5
 nokogiri-1.15.0-x64-mingw32.gem
5c26427f3cf28d8c1e43f7a7bc58e50298461c7bed5179456b122eefc2b2c5cb
 nokogiri-1.15.0-x86-linux.gem
cbf93df1c257693dfe804c01252415ca7cb9d2452d6cebddf7a35a5dbeb3ea12
 nokogiri-1.15.0-x86-mingw32.gem
ca6cd6ed08e736063539c4aa7454391dfa4153908342e3d873f5bd9218d6f644
 nokogiri-1.15.0-x86_64-darwin.gem
4b28e9151e884c10794e0acf4a6f49db933eee3cd90b20aab952ee0102a03b0c
 nokogiri-1.15.0-x86_64-linux.gem
0ca8ea2149bdaaae8db39f11971af86c83923ec58b72c519d498ec44e1dfe97f
 nokogiri-1.15.0.gem