You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on upgrading Action Text to HTML5, some tests were failing that I traced back to this repro:
classMinitest::Specdescribe"HTML4"dolet(: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"dodup=fragment.duprefute_nil(dup.document)refute_same(dup.document,fragment.document)endit"#clone makes a copy of the fragment with a new document"doclone=fragment.clonerefute_nil(clone.document)refute_same(clone.document,fragment.document)######## this fails ########endenddescribe"HTML5"dolet(: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"dodup=fragment.duprefute_nil(dup.document)refute_same(dup.document,fragment.document)endit"#clone makes a copy of the fragment with a new document"doclone=fragment.clonerefute_nil(clone.document)######## this fails ########refute_same(clone.document,fragment.document)endendend
fails with
1) Failure:
HTML4#test_0002_#clone makes a copy of the fragment with a new document [../rails/nokogiri-clone-bug.rb:54]:
Expected #<Nokogiri::HTML4::Document:0x67c name="document" children=[#<Nokogiri::XML::DTD:0x618 name="html">, #<Nokogiri::XML::Element:0x668 name="html" children=[#<Nokogiri::XML::Element:0x654 name="body" children=[#<Nokogiri::XML::Element:0x640 name="div" children=[#<Nokogiri::XML::Text:0x62c "doc">]>]>]>]> (oid=1660) to not be the same as #<Nokogiri::HTML4::Document:0x67c name="document" children=[#<Nokogiri::XML::DTD:0x618 name="html">, #<Nokogiri::XML::Element:0x668 name="html" children=[#<Nokogiri::XML::Element:0x654 name="body" children=[#<Nokogiri::XML::Element:0x640 name="div" children=[#<Nokogiri::XML::Text:0x62c "doc">]>]>]>]> (oid=1660).
2) Failure:
HTML5#test_0002_#clone makes a copy of the fragment with a new document [../rails/nokogiri-clone-bug.rb:70]:
Expected nil to not be nil.
Specifically:
HTML4::DocumentFragment#clone re-uses the original's Document
HTML5::DocumentFragment#clone does not set a document 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:
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: