Skip to content

Commit

Permalink
Fix segfault when there is no default subelement for an HTML node.
Browse files Browse the repository at this point in the history
  • Loading branch information
ender672 authored and Victor Goya committed Jun 24, 2013
1 parent b0db2a7 commit 6f97107
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Bugfixes

* (JRuby) Fix "null document" error when parsing an empty IO in jruby 1.7.3. #883
* (MRI) Fix segfault when there is no default subelement for an HTML node. #917

* Minor Enhancements

Expand Down
5 changes: 4 additions & 1 deletion ext/nokogiri/html_element_description.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ static VALUE default_sub_element(VALUE self)
htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

return NOKOGIRI_STR_NEW2(description->defaultsubelt);
if (description->defaultsubelt)
return NOKOGIRI_STR_NEW2(description->defaultsubelt);

return Qnil;
}

/*
Expand Down
5 changes: 5 additions & 0 deletions test/html/test_element_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def test_default_sub_element
assert_equal 'div', ElementDescription['body'].default_sub_element
end

def test_null_default_sub_element
doc = Nokogiri::HTML('foo')
doc.root.description.default_sub_element
end

def test_optional_attributes
attrs = ElementDescription['table'].optional_attributes
assert attrs
Expand Down

0 comments on commit 6f97107

Please sign in to comment.