-
-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Document Fragment #clone
does not behave like #dup
with respect to the owning document
#2908
Milestone
Comments
flavorjones
added
the
state/needs-triage
Inbox for non-installation-related bug reports or help requests
label
Jun 20, 2023
4 tasks
flavorjones
removed
the
state/needs-triage
Inbox for non-installation-related bug reports or help requests
label
Jun 28, 2023
@flavorjones I don't see |
@flavorjones Thanks, I'm on it. |
Just updating this since the fix for #316 (see #3117) is about to land in Nokogiri v1.17, that the tests above now only fail on the "create a new document" requirement: class Minitest::Spec
describe "HTML4" do
let(:document) { Nokogiri::HTML4::Document.parse("<div>doc</div>") }
let(:fragment) { document.fragment("<div>frag</div>") }
it "#dup makes a copy of the fragment with a new document" do
dup = fragment.dup
refute_nil(dup.document)
refute_same(dup.document, fragment.document)
end
it "#clone makes a copy of the fragment with a new document" do
clone = fragment.clone
refute_nil(clone.document)
refute_same(clone.document, fragment.document) ######## this fails ########
end
end
describe "HTML5" do
let(:document) { Nokogiri::HTML5::Document.parse("<div>doc</div>") }
let(:fragment) { document.fragment("<div>frag</div>") }
it "#dup makes a copy of the fragment with a new document" do
dup = fragment.dup
refute_nil(dup.document)
refute_same(dup.document, fragment.document)
end
it "#clone makes a copy of the fragment with a new document" do
clone = fragment.clone
refute_nil(clone.document)
refute_same(clone.document, fragment.document) ######## this fails ########
end
end
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please describe the bug
While working on upgrading Action Text to HTML5, some tests were failing that I traced back to this repro:
fails with
Specifically:
HTML4::DocumentFragment#clone
re-uses the original'sDocument
HTML5::DocumentFragment#clone
does not set adocument
at all!Expected behavior
The desired behavior matches
#dup
for node and node-like things: to make a copy of the parent document to avoid accumulating nodes that cannot be freed until the parent document is freed (see #1063 and #1834).Please also note, while we're in here, that there are expected differences between
#dup
and#clone
that we're also not honoring, see #316 for a description of those problems (essentially, the singleton class). If we tackle this issue, we should tackle that one as well.The text was updated successfully, but these errors were encountered: