{lead}
{details}
diff --git a/readability/readability.py b/readability/readability.py index 15c86c1..ddcf49f 100755 --- a/readability/readability.py +++ b/readability/readability.py @@ -276,6 +276,17 @@ def summary(self, html_partial=False, keep_all_images=False): ) if best_candidate: + # Moving a form descendant into the article would bypass + # form removal in sanitize(). + if best_candidate["elem"].xpath("ancestor-or-self::form"): + outside_form = { + elem: candidate + for elem, candidate in candidates.items() + if not elem.xpath("ancestor-or-self::form") + } + if outside_form: + candidates = outside_form + best_candidate = self.select_best_candidate(candidates) article = self.get_article( candidates, best_candidate, html_partial=html_partial ) diff --git a/tests/test_article_only.py b/tests/test_article_only.py index cb8d1ff..edeeb93 100644 --- a/tests/test_article_only.py +++ b/tests/test_article_only.py @@ -577,6 +577,28 @@ def test_preserves_lead_sibling_issue_159(self): self.assertIn(lead, summary) self.assertIn("Eligibility restrictions", summary) + def test_prefers_article_text_to_feedback_form(self): + lead = "The privacy rules explain how public agencies must handle personal information." + details = "People can request access to their records and ask an agency to correct an error." + feedback = "Tell us about your visit, your rating, your questions, your suggestions." + sample = f""" +
+{lead}
{details}