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

Fix encoding issues with % when converting svg to data url #346

Closed
wants to merge 1 commit into from

Conversation

qw-in
Copy link

@qw-in qw-in commented Aug 14, 2020

Ran into this issue in carbon

Ref carbon-app/carbon#1082

Before example

https://z4p9k.csb.app/

After example

https://zfzx1.csb.app/

@blutorange
Copy link

We had this issue to and I did a similar thing, although I opted to use encodeUriComponent so the browser can handle all edge cases

diff --git a/node_modules/dom-to-image/src/dom-to-image.js b/node_modules/dom-to-image/src/dom-to-image.js
index 27201ac..8d6a60d 100644
--- a/node_modules/dom-to-image/src/dom-to-image.js
+++ b/node_modules/dom-to-image/src/dom-to-image.js
@@ -341,7 +341,7 @@
                     foreignObject + '</svg>';
             })
             .then(function (svg) {
-                return 'data:image/svg+xml;charset=utf-8,' + svg;
+                return 'data:image/svg+xml,' + encodeURIComponent(svg);
             });
     }
 
@@ -548,7 +548,7 @@
         }
 
         function escapeXhtml(string) {
-            return string.replace(/#/g, '%23').replace(/\n/g, '%0A');
+            return string;
         }
 
         function width(node) {

@tsayen Would be really great if you could accept this PR so we could use this package without patch-package : )

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

Successfully merging this pull request may close these issues.

None yet

2 participants