@@ -727,6 +727,17 @@ def test_silencing_nonparse_errors_during_attribute_insertion_1262
727
727
assert_equal ( 0 , doc . errors . length )
728
728
end
729
729
730
+ def test_leaking_dtd_nodes_after_internal_subset_removal
731
+ # see https://github.com/sparklemotion/nokogiri/issues/1784
732
+ #
733
+ # just checking that this doesn't raise a valgrind error. we
734
+ # don't otherwise have any test coverage for removing DTDs.
735
+ #
736
+ 100 . times do |_i |
737
+ Nokogiri ::HTML ::Document . new . internal_subset . remove
738
+ end
739
+ end
740
+
730
741
it "skips encoding for script tags" do
731
742
html = Nokogiri ::HTML ( <<~EOHTML )
732
743
< html >
@@ -763,15 +774,17 @@ def test_silencing_nonparse_errors_during_attribute_insertion_1262
763
774
assert_equal "ISO-8859-1" , html . encoding . name
764
775
end
765
776
766
- def test_leaking_dtd_nodes_after_internal_subset_removal
767
- # see https://github.com/sparklemotion/nokogiri/issues/1784
768
- #
769
- # just checking that this doesn't raise a valgrind error. we
770
- # don't otherwise have any test coverage for removing DTDs.
771
- #
772
- 100 . times do |_i |
773
- Nokogiri ::HTML ::Document . new . internal_subset . remove
777
+ it "handles ill-formed processing instructions" do
778
+ html = %{<html><body><!--><?a/}
779
+ doc = Nokogiri ::HTML4 ::Document . parse ( html )
780
+ expected = if Nokogiri . jruby?
781
+ [ Nokogiri ::XML ::Node ::COMMENT_NODE , Nokogiri ::XML ::Node ::PI_NODE ]
782
+ elsif Nokogiri . libxml2_patches . include? ( "0008-htmlParseComment-handle-abruptly-closed-comments.patch" )
783
+ [ Nokogiri ::XML ::Node ::COMMENT_NODE ]
784
+ else
785
+ [ ]
774
786
end
787
+ assert_equal ( expected , doc . at_css ( "body" ) . children . map ( &:type ) )
775
788
end
776
789
777
790
describe ".parse" do
0 commit comments