Repository navigation
fix: decode base64 SVG data URIs as UTF-8 - #3093
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
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.
Summary
SvgUridecodesdata:image/svg+xml;base64,...URIs withatob, which returns one character per byte. Since #2808 (15.15.3), any SVG with non-ASCII text in a base64 data URI renders garbled:CafébecomesCafé. Before #2808,Buffer.from(content, 'base64').toString('utf-8')decoded the bytes as UTF-8.This change keeps
atob(nobufferdependency) and decodes its output as UTF-8 by percent-encoding each byte and passing the result todecodeURIComponent. If the bytes are not valid UTF-8, it returns theatoboutput unchanged, which matches the current behavior.It only affects
fetchTextinsrc/utils/fetchData.ts, used bySvgUri,SvgCssUri, andSvgFromUri.Test Plan
Added
__tests__/fetchData.test.ts, which decodes an ASCII and a UTF-8 (Café © 日本 😀) base64 data URI.Café © æ¥æ¬ ð.yarn lintandyarn tscreport nothing new.What's required for testing (prerequisites)?
An app that renders
SvgUriwith a base64 data URI whose SVG contains non-ASCII text.What are the steps to reproduce (after prerequisites)?
<SvgUri uri="data:image/svg+xml;base64,..." />where the SVG contains<text>Café</text>.Café. With the fix, it readsCafé.Compatibility
Checklist
README.md__tests__folderFixes #3092