Skip to content

Commit

Permalink
Add test and fix an issue with options parameter passing
Browse files Browse the repository at this point in the history
  • Loading branch information
JackMc committed Mar 7, 2018
1 parent 6767da7 commit cc392de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/nokogiri/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def parse thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT

####
# Parse a fragment from +string+ in to a NodeSet.
def fragment string, encoding = nil, options = nil, &block
def fragment string, encoding = nil, options = XML::ParseOptions::DEFAULT_HTML, &block
HTML::DocumentFragment.parse string, encoding, options, &block
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/nokogiri/html/document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module HTML
class DocumentFragment < Nokogiri::XML::DocumentFragment
####
# Create a Nokogiri::XML::DocumentFragment from +tags+, using +encoding+
def self.parse tags, encoding = nil, options = nil
def self.parse tags, encoding = nil, options = XML::ParseOptions::DEFAULT_HTML, &block
doc = HTML::Document.new

encoding ||= if tags.respond_to?(:encoding)
Expand All @@ -19,10 +19,10 @@ def self.parse tags, encoding = nil, options = nil

doc.encoding = encoding

new(doc, tags, nil, options)
new(doc, tags, nil, options, &block)
end

def initialize document, tags = nil, ctx = nil, options = nil, &block
def initialize document, tags = nil, ctx = nil, options = XML::ParseOptions::DEFAULT_HTML, &block
return self unless tags

if ctx
Expand Down
8 changes: 8 additions & 0 deletions test/html/test_document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def test_colons_are_not_removed
assert_match(/3:30/, doc.to_s)
end

def test_passed_options_have_an_effect
html = "<span>test</span"
doc = Nokogiri::HTML::DocumentFragment.parse(html) do |options|
options.norecover
end
assert_equal "<span>test</span>", doc.to_html
end

def test_parse_encoding
fragment = "<div>hello world</div>"
f = Nokogiri::HTML::DocumentFragment.parse fragment, 'ISO-8859-1'
Expand Down

0 comments on commit cc392de

Please sign in to comment.