Skip to content

Commit

Permalink
fixing a segfault when an empty string is sent to Node#inner_html=. c…
Browse files Browse the repository at this point in the history
…loses #88
  • Loading branch information
tenderlove committed Jul 15, 2009
1 parent 6c052aa commit c14d3b2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

* Override libxml-ruby's global error handler
* ParseOption#strict fixed
* Fixed a segfault when sending an empty string to Node#inner_html= GH #88

=== 1.3.2 / 2009-06-22

Expand Down
3 changes: 2 additions & 1 deletion lib/nokogiri/html/sax/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Parser < Nokogiri::XML::SAX::Parser
# Parse html stored in +data+ using +encoding+
def parse_memory data, encoding = 'UTF-8'
raise ArgumentError unless data
native_parse_memory(data, encoding)
return unless data.length > 0
native_parse_memory data, encoding
end

###
Expand Down
1 change: 1 addition & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$VERBOSE = true
require 'rubygems'
require 'test/unit'
require 'tempfile'

%w(../lib ../ext).each do |path|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), path)))
Expand Down
12 changes: 12 additions & 0 deletions test/html/sax/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ def setup
@parser = HTML::SAX::Parser.new(Doc.new)
end

def test_parse_empty_document
# This caused a segfault in libxml 2.6.x
assert_nothing_raised { @parser.parse '' }
end

def test_parse_empty_file
# Make sure empty files don't break stuff
empty_file_name = File.join(Dir.tmpdir, 'bogus.xml')
FileUtils.touch empty_file_name
assert_nothing_raised { @parser.parse_file empty_file_name }
end

def test_parse_file
@parser.parse_file(HTML_FILE)
assert_equal 1110, @parser.document.end_elements.length
Expand Down

0 comments on commit c14d3b2

Please sign in to comment.