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

Consider using safer/better default 'encode' function? #42

Open
derzwen opened this issue Jan 19, 2018 · 1 comment
Open

Consider using safer/better default 'encode' function? #42

derzwen opened this issue Jan 19, 2018 · 1 comment
Labels

Comments

@derzwen
Copy link

derzwen commented Jan 19, 2018

Hi,

i'm using a modified encode function in my project for month now grabbed from this very nice post without any problems:

https://codepen.io/tigt/post/optimizing-svgs-in-data-uris

Function is in this comment: https://codepen.io/tigt/post/optimizing-svgs-in-data-uris#comment-id-6931 It's feels more safe because it uses encodeURIComponent first and replaces just some characters back.

As an addition to it, I also strip the XML declaration if present after processing with something like:

svgCode.replace(/<\?xml[^>]*>/g, '');

What about using those as a default encode function?

@hudochenkov
Copy link
Collaborator

What about using those as a default encode function?

It's probably good solution, but our current solution works good as well. I don't think we need to change implementation without good reasons.

As an addition to it, I also strip the XML declaration if present after processing with something like

It's a job for SVGO. Either run it on source SVGs, or as a PostCSS plugin. This plugin does inlining only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants