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?