@@ -242,6 +242,15 @@ util.plainText = function(_str) {
242
242
return ( _str || '' ) . replace ( STRIP_TAGS , ' ' ) ;
243
243
} ;
244
244
245
+ function encodeForHTML ( _str ) {
246
+ return ( _str || '' ) . replace ( / & / g, '&' )
247
+ . replace ( / < / g, '<' )
248
+ . replace ( / > / g, '>' )
249
+ . replace ( / " / g, '"' )
250
+ . replace ( / ' / g, ''' )
251
+ . replace ( / \/ / g, '/' ) ;
252
+ }
253
+
245
254
function convertToSVG ( _str ) {
246
255
var htmlEntitiesDecoded = Plotly . util . html_entity_decode ( _str ) ;
247
256
var result = htmlEntitiesDecoded
@@ -270,15 +279,14 @@ function convertToSVG(_str) {
270
279
// remove quotes, leading '=', replace '&' with '&'
271
280
var href = extra . substr ( 4 )
272
281
. replace ( / [ " ' ] / g, '' )
273
- . replace ( / = / , '' )
274
- . replace ( / & / g, '&' ) ;
282
+ . replace ( / = / , '' ) ;
275
283
276
284
// check protocol
277
285
var dummyAnchor = document . createElement ( 'a' ) ;
278
286
dummyAnchor . href = href ;
279
287
if ( PROTOCOLS . indexOf ( dummyAnchor . protocol ) === - 1 ) return '<a>' ;
280
288
281
- return '<a xlink:show="new" xlink:href="' + href + '">' ;
289
+ return '<a xlink:show="new" xlink:href="' + encodeForHTML ( href ) + '">' ;
282
290
}
283
291
}
284
292
else if ( tag === 'br' ) return '<br>' ;
@@ -302,7 +310,7 @@ function convertToSVG(_str) {
302
310
// most of the svg css users will care about is just like html,
303
311
// but font color is different. Let our users ignore this.
304
312
extraStyle = extraStyle [ 1 ] . replace ( / ( ^ | ; ) \s * c o l o r : / , '$1 fill:' ) ;
305
- style = ( style ? style + ';' : '' ) + extraStyle ;
313
+ style = ( style ? style + ';' : '' ) + encodeForHTML ( extraStyle ) ;
306
314
}
307
315
308
316
return tspanStart + ( style ? ' style="' + style + '"' : '' ) + '>' ;
0 commit comments