Skip to content

Escape tags, lemmas and arc labels in the displaCy dependency SVG - #14088

Open
aad1tyaaaaa wants to merge 1 commit into
explosion:masterfrom
aad1tyaaaaa:fix-displacy-dep-escape
Open

aad1tyaaaaa wants to merge 1 commit into
explosion:masterfrom
aad1tyaaaaa:fix-displacy-dep-escape

Conversation

@aad1tyaaaaa

Copy link
Copy Markdown

Description

Fixes #14087.

DependencyRenderer escaped the word text but formatted the tag, the lemma and the arc label into the SVG as they were. A < or & in any of them made the SVG not well-formed, which happens with add_lemma=True on any sentence containing such a token (its lemma is the same character). This passes those three values through escape_html, as is already done for the text.

Added test_displacy_dep_escapes_tags_lemmas_and_labels (marked issue(14087)): it renders a doc with < and & in words, lemmas, tags and labels, with and without add_lemma, checks that the SVG parses as XML and that the labels are escaped. It fails without the change and passes with it. spacy/tests/test_displacy.py (27 tests) and spacy/tests/doc pass, and ruff format is clean. Tested on Windows 11 with Python 3.12.

I used an AI assistant (Claude Code) to help find the bug and write the fix and test; I reviewed and ran everything myself.

Types of change

Bug fix.

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

A '<' or '&' in a tag, lemma or dependency label made the SVG not well-formed. Fixes explosion#14087.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

displaCy dependency SVG is not well-formed when a tag, lemma or arc label contains < or &

1 participant