Skip to content

Commit

Permalink
Fixing Node#parse for HTML document nodes.
Browse files Browse the repository at this point in the history
See related commit 89db311 which broke this functionality.
  • Loading branch information
flavorjones committed Jun 21, 2014
1 parent 2aa9a20 commit 46fcdf9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.ja.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [JRuby] Fix Ruby memory exhaustion vulnerability. #1087 (Thanks, @ocher)
* [MRI] Fix segfault during GC when using `libxml-ruby` and `nokogiri` together in multi-threaded environment. #895 (Thanks, @ender672!)
* Building on OSX 10.9 stock ruby 2.0.0 now works. #1101 (Thanks, @zenspider!)
* Node#parse now works again for HTML document nodes (broken in 1.6.2+).


=== 1.6.2.1 / 2014年5月13日
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [JRuby] Fix Ruby memory exhaustion vulnerability. #1087 (Thanks, @ocher)
* [MRI] Fix segfault during GC when using `libxml-ruby` and `nokogiri` together in multi-threaded environment. #895 (Thanks, @ender672!)
* Building on OSX 10.9 stock ruby 2.0.0 now works. #1101 (Thanks, @zenspider!)
* Node#parse now works again for HTML document nodes (broken in 1.6.2+).


=== 1.6.2.1 / 2014-05-13
Expand Down
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def parse string_or_io, options = nil
# document as the parsing context instead. Otherwise, the in-context
# parser cannot find an element or a document node.
# Document Fragments are also not usable by the in-context parser.
if !element? && !xml? && (!parent || parent.fragment?)
if !element? && !is_a?(Nokogiri::XML::Document) && (!parent || parent.fragment?)
return document.parse(string_or_io, options)
end

Expand Down
24 changes: 23 additions & 1 deletion test/xml/test_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,29 @@ def test_parse_error_on_fragment_with_empty_document
def test_parse_with_unparented_text_context_node
doc = XML::Document.new
elem = XML::Text.new("foo", doc)
elem.parse("<bar/>")
x = elem.parse("<bar/>") # should not raise an exception
assert_equal x.first.name, "bar"
end

def test_parse_with_unparented_html_text_context_node
doc = HTML::Document.new
elem = XML::Text.new("div", doc)
x = elem.parse("<div/>") # should not raise an exception
assert_equal x.first.name, "div"
end

def test_parse_with_unparented_fragment_text_context_node
doc = XML::DocumentFragment.parse "<div><span>foo</span></div>"
elem = doc.at_css "span"
x = elem.parse("<span/>") # should not raise an exception
assert_equal x.first.name, "span"
end

def test_parse_with_unparented_html_fragment_text_context_node
doc = HTML::DocumentFragment.parse "<div><span>foo</span></div>"
elem = doc.at_css "span"
x = elem.parse("<span/>") # should not raise an exception
assert_equal x.first.name, "span"
end

def test_subclass_dup
Expand Down

0 comments on commit 46fcdf9

Please sign in to comment.