Repository navigation
Escape tags, lemmas and arc labels in the displaCy dependency SVG - #14088
Open
aad1tyaaaaa wants to merge 1 commit into
Open
aad1tyaaaaa wants to merge 1 commit into
aad1tyaaaaa wants to merge 1 commit into
Conversation
A '<' or '&' in a tag, lemma or dependency label made the SVG not well-formed. Fixes explosion#14087.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #14087.
DependencyRendererescaped 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 withadd_lemma=Trueon any sentence containing such a token (its lemma is the same character). This passes those three values throughescape_html, as is already done for the text.Added
test_displacy_dep_escapes_tags_lemmas_and_labels(markedissue(14087)): it renders a doc with<and&in words, lemmas, tags and labels, with and withoutadd_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) andspacy/tests/docpass, andruff formatis 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