Repository navigation
🐛 fix(linkify): escape text of raw-text roots in string output - #2249
Merged
Merged
Conversation
linkify and Linker.linkify return the linked node as an HTML string. When the node was a raw-text element such as style or xmp, the serializer wrote its text verbatim, so the string could carry markup the node held only as text. The string is read as plain content, so the root's children now go under a plain element before they are serialized. The tree form, linkify_node, still returns the node, and other roots serialize as before. Fixes tox-dev#2245
A string is parsed under a div, so its root is never a raw-text element. Returning for a string before the root check keeps the string form's work unchanged for the common input. Refs tox-dev#2245
…c-fix/linkify-rawtext
Merging this PR will improve performance by 15.56%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
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.
linkify(node),Linker.linkify(node)andlinkify(node, options)return the linked node as an HTML string. When that node is a raw-text element (style,script,xmp,iframe,noembed,noframesorplaintext), the string carried the node's text unescaped, so it did not read back as the text the node held. After this change the text comes back escaped, as it already does fortextarea,title,noscriptand a plaindiv. Fixes #2245.The string form returns the serializer's output for the node itself, from the return line of
Linker.linkify.The root's content model picked how its text was written
The HTML serialization algorithm writes the children of a raw-text element without escaping (serialising HTML fragments). turbohtml follows it in
is_rawtext_elementand in the raw-text writer. The string form asked for the root'sinner_html, so the root's own element decided how its text was written. The returned string has no raw-text context, so a reader of the string sees that text as ordinary content.The children go under a plain element before serialization
For a raw-text root, the copy's children now move under a fresh
div, and the string is that element'sinner_html(new lines). This is the route thesanitizestring forms take for the same shape. Element children keep their markup, as they do under any element, and the caller's node is untouched because only the copy is moved.Behavior changes
linkify,Linker.linkifyand theoptionsform for a raw-text root escapes&,<and>in its text, where it previously wrote them as they were.inner_html, and this change leaves the serializer as it is.linkify_nodereturns the node and is unchanged, so serializing that node directly still writes a raw-text root's text as written.