Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Oct 5, 2024
1 parent 5a4a9c3 commit d411303
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
3 changes: 3 additions & 0 deletions lib/nokogiri/xml/document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
module Nokogiri
module XML
class DocumentFragment < Nokogiri::XML::Node
attr_reader :parse_options

####
# Create a Nokogiri::XML::DocumentFragment from +tags+
def self.parse(tags, options = ParseOptions::DEFAULT_XML, &block)
Expand All @@ -20,6 +22,7 @@ def initialize(document, tags = nil, ctx = nil, options = ParseOptions::DEFAULT_
return self unless tags

options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
@parse_options = options
yield options if block_given?

children = if ctx
Expand Down
9 changes: 2 additions & 7 deletions test/html4/sax/test_document_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@ def start_document
end

def test_warning_document_encounters_error_but_terminates_normally
# Probably I'm doing something wrong, but I can't make nekohtml report errors,
# despite setting http://cyberneko.org/html/features/report-errors.
# See https://nekohtml.sourceforge.net/settings.html for more info.
# I'd love some help here if someone finds this comment and cares enough to dig in.
skip_unless_libxml2("nekohtml sax parser does not seem to report errors?")

warning_parser = Nokogiri::HTML4::SAX::Parser.new(Nokogiri::SAX::TestCase::Doc.new)
warning_parser.parse("<html><body><<div att=")
refute_empty(warning_parser.document.errors, "error collector did not collect an error")

assert(warning_parser.end_document_called)
end
end
end
5 changes: 2 additions & 3 deletions test/html4/test_document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,16 +431,15 @@ def test_parse_with_io

describe "HTML4::DocumentFragment.new" do
describe "without a context node" do
it "has sane defaults" do
it "has reasonable defaults" do
frag = Nokogiri::HTML4::DocumentFragment.new(Nokogiri::HTML4::Document.new, input)
assert_equal("<div>foo</div>", frag.to_html)
refute_empty(frag.errors)
end

it "accepts options" do
frag = Nokogiri::HTML4::DocumentFragment.new(Nokogiri::HTML4::Document.new, input, nil, html4_default)
assert_equal html4_default, frag.parse_options
assert_equal("<div>foo</div>", frag.to_html)
refute_empty(frag.errors)

assert_raises(Nokogiri::SyntaxError) do
Nokogiri::HTML4::DocumentFragment.new(Nokogiri::HTML4::Document.new, input, nil, html4_strict)
Expand Down

0 comments on commit d411303

Please sign in to comment.