Skip to content

Commit

Permalink
Fix m-070
Browse files Browse the repository at this point in the history
- Treat glossary values as string literals, not patterns
- Search for glossary values surrounded by word boundaries
  • Loading branch information
apasel422 committed Jul 13, 2024
1 parent 21dd6d5 commit ab2b45e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3619,7 +3619,7 @@ def lint(self, skip_lint_ignore: bool, allowed_messages: Optional[List[str]] = N
nodes = dom.xpath("/html/body//dd[contains(@epub:type, 'glossdef')]")
source_text = " ".join([node.inner_text() for node in nodes])
for glossary_index, glossary_value in enumerate(glossary_usage):
if glossary_value[1] is False and regex.search(glossary_value[0], source_text, flags=regex.IGNORECASE):
if glossary_value[1] is False and regex.search(r"\b\L<val>\b", source_text, flags=regex.IGNORECASE, val=[glossary_value[0]]):
glossary_usage[glossary_index] = (glossary_value[0], True)

# Test against word boundaries to not match `halftitlepage`
Expand Down
2 changes: 1 addition & 1 deletion tests/lint/metadata/m-070/golden/m-070-out.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m-070 [Error] glossary-search-key-map.xml Glossary entry not found in the text.
R+L=J
foo
2 changes: 0 additions & 2 deletions tests/lint/metadata/m-070/in/src/epub/text/chapter-1.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
<body epub:type="bodymatter z3998:fiction">
<section id="chapter-1" epub:type="chapter">
<h2 epub:type="ordinal z3998:roman">I</h2>
<!-- erroneously considered to match the glossary term "foo" -->
<p>He ate some food.</p>
<!-- erroneously unmatched due to treatment of glossary term as a regex -->
<p>A common theory was R+L=J.</p>
</section>
</body>
Expand Down

0 comments on commit ab2b45e

Please sign in to comment.