Skip to content

Commit 22d902b

Browse files
committed
Snapshot: Strip double quotation marks from font-family strings and return proper url for svg downloads
1 parent ef6efd7 commit 22d902b

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

src/snapshot/svgtoimg.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function svgToImg(opts) {
8686
imgData = canvas.toDataURL('image/webp');
8787
break;
8888
case 'svg':
89-
imgData = svg;
89+
imgData = url;
9090
break;
9191
default:
9292
reject(new Error('Image format is not jpeg, png or svg'));

src/snapshot/tosvg.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,12 @@ module.exports = function toSVG(gd, format) {
7878
return;
7979
}
8080

81-
// I've seen font-family styles with non-escaped double quotes in them - breaks the
82-
// serialized svg because the style attribute itself is double-quoted!
83-
// Is this an IE thing? Any other attributes or style elements that can have quotes in them?
84-
// TODO: this looks like a noop right now - what happened to it?
85-
86-
/*
87-
* Font-family styles with double quotes in them breaks the to-image
88-
* step in FF42 because the style attribute itself is wrapped in
89-
* double quotes. See:
90-
*
91-
* - http://codepen.io/etpinard/pen/bEdQWK
92-
* - https://github.com/plotly/plotly.js/pull/104
93-
*
94-
* for more info.
95-
*/
81+
// Font family styles break things because of quotation marks,
82+
// so we must remove them *after* the SVG DOM has been serialized
83+
// to a string (browsers convert singles back)
9684
var ff = txt.style('font-family');
9785
if(ff && ff.indexOf('"') !== -1) {
98-
txt.style('font-family', ff.replace(/"/g, '\\\''));
86+
txt.style('font-family', ff.replace(/"/g, 'TOBESTRIPPED'));
9987
}
10088
});
10189

@@ -115,5 +103,8 @@ module.exports = function toSVG(gd, format) {
115103
s = svgTextUtils.html_entity_decode(s);
116104
s = svgTextUtils.xml_entity_encode(s);
117105

106+
// Fix quotations around font strings
107+
s = s.replace(/("TOBESTRIPPED)|(TOBESTRIPPED")/g, '\'');
108+
118109
return s;
119110
};

0 commit comments

Comments
 (0)