Skip to content

fix(crossref): strip JATS markup from abstracts - #13525

Merged
kodjima33 merged 3 commits into
BasedHardware:mainfrom
Nukeys:fix/crossref-strip-jats
Sep 12, 2026
Merged

kodjima33 merged 3 commits into
BasedHardware:mainfrom
Nukeys:fix/crossref-strip-jats

Conversation

@Nukeys

@Nukeys Nukeys commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #13242.

clean() now removes jats tags and generic HTML tags from Crossref abstracts.

  • Unit tests
  • Failure-Class: none

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 as a<b into a and 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

Comment thread plugins/omi-crossref-app/main.py Outdated
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
value = re.sub(r"</?[a-zA-Z][^>]*>", "", value)
value = re.sub(r"(?<![A-Za-z0-9_])</?[a-zA-Z][^>]*>", "", value)

@Nukeys

Nukeys commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Fixed: tag strip requires a non-word character before <, so inequalities like a<b are preserved. Added a regression test.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 &amp; B <b>bold</b>") returns "A & B bold</b>" — a stray </b> left in the chat output. That is exactly the assertion in test_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 local python -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.

@Git-on-my-level Git-on-my-level added python positive-signal Automation verified a genuine fix/quality contribution labels Sep 12, 2026
@Nukeys

Nukeys commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Fixed: closing tags strip unconditionally; open tags keep the inequality lookbehind. Added text</p> regression. pytest test_clean.py 4 passed.

@Nukeys

Nukeys commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

@Git-on-my-level Ready for re-review. All requested changes are pushed on the latest head.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Community bug-fix 5/5: current head already fixes the closing-tag regex gap flagged in review (verified independently), tests cover it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

positive-signal Automation verified a genuine fix/quality contribution python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crossref work lookup returns raw JATS markup in the abstract

3 participants