Permalink
Browse files

Better way of ensuring that a valid Nokokogiri::HTML::Document is ret…

…urned from make_html
  • Loading branch information...
1 parent a034fde commit ff9b6786fbf760c818c9da94ffc5ea84d1e6c154 @jrust jrust committed Apr 9, 2012
Showing with 3 additions and 6 deletions.
  1. +3 −6 lib/readability.rb
View
@@ -20,7 +20,7 @@ class Document
def initialize(input, options = {})
@options = DEFAULT_OPTIONS.merge(options)
- @input = fix_blank_input(input)
+ @input = input
if RUBY_VERSION =~ /^1\.9\./ && !@options[:encoding]
@input = GuessHtmlEncoding.encode(@input, @options[:html_headers]) unless @options[:do_not_guess_encoding]
@@ -46,6 +46,8 @@ def prepare_candidates
def make_html
@html = Nokogiri::HTML(@input, nil, @options[:encoding])
+ # In case Nokogiri returns an empty document which can happen, for example, if @input is an empty string
+ @html = Nokogiri::HTML('<body />', nil, @options[:encoding]) if @html.children.length == 1
end
def images(content=nil, reload=false)
@@ -408,10 +410,5 @@ def clean_conditionally(node, candidates, selector)
end
end
end
-
- protected
- def fix_blank_input(input)
- input.empty? ? '<body />' : ''
- end
end
end

0 comments on commit ff9b678

Please sign in to comment.