Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URI encoding in the svg function results in a broken data URI #130

Open
PitchforkAssistant opened this issue Dec 14, 2024 · 0 comments
Open

Comments

@PitchforkAssistant
Copy link
Contributor

The svg helper function calls encodeURIComponent on the provided SVG before returning it. Based on the comment above the return line, that appears to be intentional as a fix for some different issue. Encoding the data like this completely breaks the data URI, resulting in a missing image placeholder on both Shreddit and the Android app (iOS untested).

// Return the sanitized SVG string as a data URI
// This fixes things like hexadecimal colors that URLs treat as special characters!
return `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(str)}`;

If the point of the URI encoding is to avoid issues with special characters, perhaps it would be best to instead encode it as a base64 string? From testing with local modifications, changing the return line to this appears to work as far as the SVG actually showing up is concerned:

return `data:image/svg+xml;base64,${Buffer.from(str).toString('base64')}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant