From 90e874e3118f0fbb6e1a6f30cd8087c9db841f74 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Thu, 17 Apr 2014 11:59:20 +0200 Subject: [PATCH] Fix undefined local variable 'name' --- lib/readability.rb | 4 ++-- spec/readability_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/readability.rb b/lib/readability.rb index 30106df..1de9244 100644 --- a/lib/readability.rb +++ b/lib/readability.rb @@ -455,7 +455,7 @@ def clean_conditionally(node, candidates, selector) content_length = el.text.strip.length # Count the text length excluding any surrounding whitespace link_density = get_link_density(el) - reason = clean_conditionally_reason?(counts, content_length, options, weight, link_density) + reason = clean_conditionally_reason?(name, counts, content_length, options, weight, link_density) if reason debug("Conditionally cleaned #{name}##{el[:id]}.#{el[:class]} with weight #{weight} and content score #{content_score} because it has #{reason}.") el.remove @@ -464,7 +464,7 @@ def clean_conditionally(node, candidates, selector) end end - def clean_conditionally_reason?(counts, content_length, options, weight, link_density) + def clean_conditionally_reason?(name, counts, content_length, options, weight, link_density) if counts["img"] > counts["p"] "too many images" elsif counts["li"] > counts["p"] && name != "ul" && name != "ol" diff --git a/spec/readability_spec.rb b/spec/readability_spec.rb index 8e98ddc..ae6f810 100644 --- a/spec/readability_spec.rb +++ b/spec/readability_spec.rb @@ -541,4 +541,13 @@ end end + + describe "clean_conditionally_reason?" do + let (:list_fixture) { "

test

#{'
  • ' * 102}" } + + it "does not raise error" do + @doc = Readability::Document.new(list_fixture) + expect { @doc.content }.to_not raise_error + end + end end