Skip to content

HTML::DocumentFragment.parse should be able to accept an IO object #2069

@flavorjones

Description

@flavorjones

Describe the bug

HTML4::Document.parse, HTML5::Document.parse, and HTML5::DocumentFragment.parse all accept IO objects.

But HTML4::DocumentFragment.parse raises an unobvious exception when we do this.

To Reproduce

#! /usr/bin/env ruby
puts Nokogiri::HTML4::DocumentFragment.parse(StringIO.new("<div>hello</div>"))

emits:

/home/flavorjones/code/oss/nokogiri/lib/nokogiri/html4/document_fragment.rb:40:in `match?': no implicit conversion of StringIO into String (TypeError)

          path = if /^\s*?<body/i.match?(tags)
                                         ^^^^
        from /home/flavorjones/code/oss/nokogiri/lib/nokogiri/html4/document_fragment.rb:40:in `initialize'
        from /home/flavorjones/code/oss/nokogiri/lib/nokogiri/html4/document_fragment.rb:24:in `new'
        from /home/flavorjones/code/oss/nokogiri/lib/nokogiri/html4/document_fragment.rb:24:in `parse'
        from (irb):5:in `<main>'

Expected behavior

I'd like the HTML4::DocumentFragment.parse method(s) be able to handle an IO object, even if that means we just #read the whole string into a String.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions