Skip to content

Commit

Permalink
fix(jruby): write_to enc falls back to document encoding
Browse files Browse the repository at this point in the history
This is what libxml2's `xmlsave.c` functions do, so let's make it
explicit in the caller so that JRuby has the same behavior.
  • Loading branch information
flavorjones committed Mar 1, 2023
1 parent 9b72eaf commit 937d9aa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA
### Fixed

* [JRuby] Serializing an HTML4 document with `#write_to` and specifying no save options will properly emit an HTML document anyway, like libxml2 does. Previously JRuby emitted XML in this situation.
* [JRuby] Serializing with `#write_to` will fall back to the document encoding when no encoding is specified, like libxml2 does. Previously JRuby emitted UTF-8 in this situation.


### Improved
Expand Down
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ def to_xhtml(options = {})
#
def write_to(io, *options)
options = options.first.is_a?(Hash) ? options.shift : {}
encoding = options[:encoding] || options[0]
encoding = options[:encoding] || options[0] || document.encoding
if Nokogiri.jruby?
save_options = options[:save_with] || options[1]
indent_times = options[:indent] || 0
Expand Down

0 comments on commit 937d9aa

Please sign in to comment.