Skip to content

Commit

Permalink
4165 - Use Nokogiri at_css instead of css as the former returns nil r…
Browse files Browse the repository at this point in the history
…ather than the whole document if the element is not found
  • Loading branch information
ariana-paris committed Dec 3, 2014
1 parent edac6d4 commit 8fea914
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/story_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def parse_common(story, location = nil, encoding = nil)
@doc = Nokogiri::HTML.parse(story, nil, encoding) rescue ""

# Try to convert all relative links to absolute
base = @doc.css('base').present? ? @doc.css('base')[0]['href'] : location.split('?').first
base = @doc.at_css('base') ? @doc.css('base')[0]['href'] : location.split('?').first
if base.present?
@doc.css('a').each do |link|
if link['href'].present?
Expand Down Expand Up @@ -547,8 +547,8 @@ def parse_story_from_unknown(story)
work_params = {:chapter_attributes => {}}
storyhead = @doc.css("head").inner_html if @doc.css("head")
# Story content - Look for progressively less specific containers or grab everything
element = @doc.css('.chapter-content') || @doc.css('body') || @doc.css('html')
storytext = element.present? ? element.inner_html : story
element = @doc.at_css('.chapter-content') || @doc.at_css('body') || @doc.at_css('html') || @doc
storytext = element.inner_html

meta = {}
unless storyhead.blank?
Expand Down

0 comments on commit 8fea914

Please sign in to comment.