Skip to content

Commit 29f6a53

Browse files
authored
Merge pull request #328 from renatodvc/fix/markup-clean-steps-default
Fix get_citations(markup_text=...) crashing without an "html" clean step
2 parents 8a57f13 + 6306710 commit 29f6a53

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Changes:
1111
-
1212

1313
Fixes:
14-
-
14+
- Fix 2 `TypeError`s raised in `get_citations(markup_text=...)` when
15+
`clean_steps` was omitted or lacked `"html"`. The documented fallback that
16+
prepends the `html` step was both unreachable and broken.
1517

1618
## Current
1719

eyecite/models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,11 +930,13 @@ def __post_init__(self):
930930
elif self.markup_text and not self.plain_text:
931931
self.source_text = self.markup_text
932932

933-
if "html" not in self.clean_steps:
934-
self.clean_steps.insert("html", 0)
933+
clean_steps = list(self.clean_steps or [])
934+
if "html" not in clean_steps:
935+
clean_steps.insert(0, "html")
935936
logger.warning(
936937
"`html` has been added to `markup_text` clean_steps list"
937938
)
939+
self.clean_steps = clean_steps
938940

939941
self.plain_text = clean_text(self.markup_text, self.clean_steps)
940942

tests/test_FindTest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,33 @@ def test_reference_filtering(self):
14061406
any(isinstance(cite, ReferenceCitation) for cite in citations)
14071407
)
14081408

1409+
def test_markup_text_without_html_clean_step(self) -> None:
1410+
"""Does passing `markup_text` without an `html` clean step auto-add
1411+
it (with a warning) instead of crashing?
1412+
1413+
"""
1414+
markup = "<p>Lissner v. Test, <i>1 U.S. 1</i> (1982)</p>"
1415+
1416+
# clean_steps omitted entirely (get_citations defaults it to None)
1417+
with self.assertLogs("eyecite.models", level="WARNING") as logs:
1418+
cites = get_citations(markup_text=markup)
1419+
self.assertEqual([c.matched_text() for c in cites], ["1 U.S. 1"])
1420+
self.assertTrue(
1421+
any("`html` has been added" in line for line in logs.output)
1422+
)
1423+
1424+
# clean_steps provided but missing "html", must prepend it
1425+
with self.assertLogs("eyecite.models", level="WARNING"):
1426+
cites = get_citations(
1427+
markup_text=markup, clean_steps=["all_whitespace"]
1428+
)
1429+
self.assertEqual([c.matched_text() for c in cites], ["1 U.S. 1"])
1430+
1431+
# clean_steps already containing "html" stays untouched and quiet
1432+
with self.assertNoLogs("eyecite.models", level="WARNING"):
1433+
cites = get_citations(markup_text=markup, clean_steps=["html"])
1434+
self.assertEqual([c.matched_text() for c in cites], ["1 U.S. 1"])
1435+
14091436
def test_markup_plaintiff_and_antecedent_guesses(self) -> None:
14101437
# Can we identify full case names in markup text
14111438
test_pairs = (

0 commit comments

Comments
 (0)