Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c4d4a4c

Browse files
committed
Snapshot: Strip double quotation marks from font-family strings and return proper url for svg downloads
# Conflicts: # src/snapshot/svgtoimg.js
1 parent dc5c7c8 commit c4d4a4c

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/snapshot/tosvg.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,12 @@ module.exports = function toSVG(gd, format) {
125125
return;
126126
}
127127

128-
// I've seen font-family styles with non-escaped double quotes in them - breaks the
129-
// serialized svg because the style attribute itself is double-quoted!
130-
// Is this an IE thing? Any other attributes or style elements that can have quotes in them?
131-
// TODO: this looks like a noop right now - what happened to it?
132-
133-
/*
134-
* Font-family styles with double quotes in them breaks the to-image
135-
* step in FF42 because the style attribute itself is wrapped in
136-
* double quotes. See:
137-
*
138-
* - http://codepen.io/etpinard/pen/bEdQWK
139-
* - https://github.com/plotly/plotly.js/pull/104
140-
*
141-
* for more info.
142-
*/
128+
// Font family styles break things because of quotation marks,
129+
// so we must remove them *after* the SVG DOM has been serialized
130+
// to a string (browsers convert singles back)
143131
var ff = txt.style('font-family');
144132
if(ff && ff.indexOf('"') !== -1) {
145-
txt.style('font-family', ff.replace(/"/g, '\\\''));
133+
txt.style('font-family', ff.replace(/"/g, 'TOBESTRIPPED'));
146134
}
147135
});
148136

@@ -162,6 +150,9 @@ module.exports = function toSVG(gd, format) {
162150
s = svgTextUtils.html_entity_decode(s);
163151
s = svgTextUtils.xml_entity_encode(s);
164152

153+
// Fix quotations around font strings
154+
s = s.replace(/("TOBESTRIPPED)|(TOBESTRIPPED")/g, '\'');
155+
165156
return s;
166157
};
167158

0 commit comments

Comments
 (0)