From 8bd6c6dd3b7b2cca3911e070dd85475ef203187b Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 12 Dec 2024 14:39:11 -0500 Subject: [PATCH] fix(jruby): XML::DocumentFragment.dup to another document Back in b92660e6 (#1834 fixing #1063) I omitted support in JRuby for the "new_parent_document" argument to `Node#dup` because there was no performance reason to implement it. So the test was skipped. However, in 1e7d38af and other commits in #3117 (fixing #316), I introduced a call to `initialize_copy_with_args` that passes the new parent document as an argument on both CRuby and JRuby implementations. Because the test was skipped, I didn't catch that this broke on JRuby. In particular this was a problem for Loofah which relies on decorators, and even more particularly this broke the `Loofah::TextBehavior` formatting concern for `Loofah::*::DocumentFragment` objects. Maybe we should be running downstream tests with JRuby, too? But that feels like a big investment right now so I'll avoid scarring on the first cut, and wait to see if it happens again. (cherry picked from commit dda0be29715f33ca0066ebc831dae93e3000f9d0) --- ext/java/nokogiri/XmlNode.java | 3 ++- test/xml/test_node.rb | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/java/nokogiri/XmlNode.java b/ext/java/nokogiri/XmlNode.java index 70440b53512..c74650cd6b9 100644 --- a/ext/java/nokogiri/XmlNode.java +++ b/ext/java/nokogiri/XmlNode.java @@ -978,10 +978,11 @@ public class XmlNode extends RubyObject @JRubyMethod(visibility = Visibility.PROTECTED) public IRubyObject - initialize_copy_with_args(ThreadContext context, IRubyObject other, IRubyObject level, IRubyObject _ignored) + initialize_copy_with_args(ThreadContext context, IRubyObject other, IRubyObject level, IRubyObject document) { boolean deep = level instanceof RubyInteger && RubyFixnum.fix2int(level) != 0; this.node = asXmlNode(context, other).node.cloneNode(deep); + setDocument(context, (XmlDocument)document); return this; } diff --git a/test/xml/test_node.rb b/test/xml/test_node.rb index 543e34c08c6..641b0dce5b6 100644 --- a/test/xml/test_node.rb +++ b/test/xml/test_node.rb @@ -238,8 +238,6 @@ def test_dup_same_parent_document_is_default end def test_dup_different_parent_document - skip_unless_libxml2("Node.dup with new_parent arg is only implemented on CRuby") - doc1 = XML::Document.parse("

hello

") doc2 = XML::Document.parse("
")