Skip to content

Commit

Permalink
Merge pull request #1713 from sparklemotion/flavorjones-1238-segfault…
Browse files Browse the repository at this point in the history
…-reparented-entities

issue #1238 segfault on predefined entities
  • Loading branch information
flavorjones authored Jan 28, 2018
2 parents bf94cf5 + b1494e5 commit 6e14afe
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
## Bug fixes

* Node#serialize once again returns UTF-8-encoded strings. [#1659]
* [JRuby] made SAX parsing of characters consistent with C implementation [#1676] (Thanks, @andrew-aladev!)


# 1.8.1 / 2017-09-19
Expand Down
5 changes: 3 additions & 2 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ lib/nokogiri/xml/dtd.rb
lib/nokogiri/xml/element_content.rb
lib/nokogiri/xml/element_decl.rb
lib/nokogiri/xml/entity_decl.rb
lib/nokogiri/xml/entity_reference.rb
lib/nokogiri/xml/namespace.rb
lib/nokogiri/xml/node.rb
lib/nokogiri/xml/node/save_options.rb
Expand Down Expand Up @@ -297,8 +298,8 @@ test/files/xinclude.xml
test/helper.rb
test/html/sax/test_parser.rb
test/html/sax/test_parser_context.rb
test/html/sax/test_push_parser.rb
test/html/sax/test_parser_text.rb
test/html/sax/test_push_parser.rb
test/html/test_builder.rb
test/html/test_document.rb
test/html/test_document_encoding.rb
Expand All @@ -325,8 +326,8 @@ test/xml/node/test_save_options.rb
test/xml/node/test_subclass.rb
test/xml/sax/test_parser.rb
test/xml/sax/test_parser_context.rb
test/xml/sax/test_push_parser.rb
test/xml/sax/test_parser_text.rb
test/xml/sax/test_push_parser.rb
test/xml/test_attr.rb
test/xml/test_attribute_decl.rb
test/xml/test_builder.rb
Expand Down
1 change: 1 addition & 0 deletions lib/nokogiri/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
require 'nokogiri/xml/reader'
require 'nokogiri/xml/notation'
require 'nokogiri/xml/entity_decl'
require 'nokogiri/xml/entity_reference'
require 'nokogiri/xml/schema'
require 'nokogiri/xml/relax_ng'

Expand Down
18 changes: 18 additions & 0 deletions lib/nokogiri/xml/entity_reference.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Nokogiri
module XML
class EntityReference < Nokogiri::XML::Node
def children
# libxml2 will create a malformed child node for predefined
# entities. because any use of that child is likely to cause a
# segfault, we shall pretend that it doesn't exist.
#
# see https://github.com/sparklemotion/nokogiri/issues/1238 for details
NodeSet.new(document)
end

def inspect_attributes
[:name]
end
end
end
end
11 changes: 11 additions & 0 deletions test/xml/test_entity_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def test_newline_node
doc.xpath('/item').first.add_child(lf_node)
assert_match(/&#xa;/, doc.to_xml)
end

def test_children_should_always_be_empty
# https://github.com/sparklemotion/nokogiri/issues/1238
#
# libxml2 will create a malformed child node for predefined
# entities. because any use of that child is likely to cause a
# segfault, we shall pretend that it doesn't exist.
entity = Nokogiri::XML::EntityReference.new(@xml, "amp")
assert_equal 0, entity.children.length
entity.inspect # should not segfault
end
end

module Common
Expand Down

0 comments on commit 6e14afe

Please sign in to comment.