Repository navigation
fix(crossref): strip JATS markup from abstracts - #13525
Conversation
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 3/5
- In
plugins/omi-crossref-app/main.py,clean()can strip legitimate abstract text that resembles an HTML tag, corrupting content such asa<bintoaand potentially affecting other cleaned fields; tighten the tag detection or use markup-aware parsing before merging.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="plugins/omi-crossref-app/main.py">
<violation number="1" location="plugins/omi-crossref-app/main.py:34">
P2: The generic tag regex `</?[a-zA-Z][^>]*>` also removes legitimate non-markup content in abstracts, e.g. an inequality "a<b" becomes "a" (verified: "If a<b, then c>d." → "If ad."). Since `clean()` also processes DOI/URL/title fields, any of those containing '<letter>' is corrupted too. Restrict tag-stripping to the abstract field and make the pattern only match real markup rather than any angle-bracketed word, e.g. require the '<' to not be preceded by a word character: `re.sub(r"(?<![A-Za-z0-9_])</?[a-zA-Z][^>]*>", "", value)`.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| value = html.unescape(str(text)).strip() | ||
| # Crossref abstracts often carry JATS markup; chat tools want plain text. | ||
| value = _JATS_TAG.sub("", value) | ||
| value = re.sub(r"</?[a-zA-Z][^>]*>", "", value) |
There was a problem hiding this comment.
P2: The generic tag regex </?[a-zA-Z][^>]*> also removes legitimate non-markup content in abstracts, e.g. an inequality "a<b" becomes "a" (verified: "If a<b, then c>d." → "If ad."). Since clean() also processes DOI/URL/title fields, any of those containing '<letter>' is corrupted too. Restrict tag-stripping to the abstract field and make the pattern only match real markup rather than any angle-bracketed word, e.g. require the '<' to not be preceded by a word character: re.sub(r"(?<![A-Za-z0-9_])</?[a-zA-Z][^>]*>", "", value).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At plugins/omi-crossref-app/main.py, line 34:
<comment>The generic tag regex `</?[a-zA-Z][^>]*>` also removes legitimate non-markup content in abstracts, e.g. an inequality "a<b" becomes "a" (verified: "If a<b, then c>d." → "If ad."). Since `clean()` also processes DOI/URL/title fields, any of those containing '<letter>' is corrupted too. Restrict tag-stripping to the abstract field and make the pattern only match real markup rather than any angle-bracketed word, e.g. require the '<' to not be preceded by a word character: `re.sub(r"(?<![A-Za-z0-9_])</?[a-zA-Z][^>]*>", "", value)`.</comment>
<file context>
@@ -13,18 +14,25 @@
+ value = html.unescape(str(text)).strip()
+ # Crossref abstracts often carry JATS markup; chat tools want plain text.
+ value = _JATS_TAG.sub("", value)
+ value = re.sub(r"</?[a-zA-Z][^>]*>", "", value)
+ return value.strip()
</file context>
| value = re.sub(r"</?[a-zA-Z][^>]*>", "", value) | |
| value = re.sub(r"(?<![A-Za-z0-9_])</?[a-zA-Z][^>]*>", "", value) |
|
Fixed: tag strip requires a non-word character before |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the fix and for the tight test coverage — the diagnosis in #13242 is spot-on, and stripping both JATS and generic HTML inside clean() is the right place for it. One blocking bug on the current head, though: the PR fails one of its own new tests.
plugins/omi-crossref-app/main.py — the lookbehind on _HTML_TAG breaks closing tags
_HTML_TAG = re.compile(r"(?<![A-Za-z0-9_])</?[a-zA-Z][^>]*>")The lookbehind (?<![A-Za-z0-9_]) applies to closing tags too, and a closing tag is almost always preceded by a word character (the text it wraps), so </b>, </i>, </sub> etc. survive stripping:
clean("A & B <b>bold</b>")returns"A & B bold</b>"— a stray</b>left in the chat output. That is exactly the assertion intest_clean_unescapes_entities_and_strips_generic_tags, so the new suite is red against the new implementation. Worth flagging because no CI checks run on this PR, so it only shows up on a localpython -m pytest test_clean.py.- The JATS test still passes only because
_JATS_TAG(no lookbehind) removes</jats:...>first; generic HTML has no such fallback.
Suggested fix — the inequality guard only needs to protect open tags (a<b can't be a closing tag; a</b> can't be math), so strip closers unconditionally:
_CLOSE_TAG = re.compile(r"</[a-zA-Z][^>]*>")
_OPEN_TAG = re.compile(r"(?<![A-Za-z0-9_])<[a-zA-Z][^>]*>")and in clean():
value = _JATS_TAG.sub("", value)
value = _CLOSE_TAG.sub("", value)
value = _OPEN_TAG.sub("", value)I ran this variant against all three tests in plugins/omi-crossref-app/test_clean.py plus extras ("text</p> tail", "p<0.05 was <i>significant</i> here") and everything passes, including the inequality case. Known residual tradeoff of the guard, in either version: an open tag directly after a word character (e.g. <sub> in H<sub>2</sub>O) is kept to protect a<b-style math — rare in Crossref abstracts and strictly better than leaking JATS.
plugins/omi-crossref-app/test_clean.py — coverage is good as-is; with the fix above nothing new is strictly required, though a case like clean("text</p> tail") == "text tail" would lock in the closing-tag behavior the current lookbehind breaks.
Once the regex is adjusted and test_clean_unescapes_entities_and_strips_generic_tags passes locally, this looks good to go — happy to re-review. Requesting changes only for that; the rest (version bump to 1.0.1, test layout) is fine.
Posted by the Omi maintainer automation on behalf of the maintainers; no product decision needed — normal re-review after the fix.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Fixed: closing tags strip unconditionally; open tags keep the inequality lookbehind. Added |
|
@Git-on-my-level Ready for re-review. All requested changes are pushed on the latest head. |
kodjima33
left a comment
There was a problem hiding this comment.
Community bug-fix 5/5: current head already fixes the closing-tag regex gap flagged in review (verified independently), tests cover it.
Closes #13242.
clean()now removes jats tags and generic HTML tags from Crossref abstracts.