Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit c741b3b

Browse files
committed
Escape HTML in SVG text renderer
1 parent e451bdc commit c741b3b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/core/svgRenderer.coffee

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ renderShapeToSVG = (shape, opts={}) ->
1818
else
1919
throw "Can't render shape of type #{shape.className} to SVG"
2020

21+
entityMap = {
22+
'&': '&',
23+
'<': '&lt;',
24+
'>': '&gt;',
25+
'"': '&quot;',
26+
"'": '&#39;',
27+
'/': '&#x2F;',
28+
'`': '&#x60;',
29+
'=': '&#x3D;'
30+
}
31+
32+
escapeHTML = (string) -> String(string).replace /[&<>"'`=\/]/g, (s) -> entityMap[s]
33+
2134

2235
defineSVGRenderer 'Rectangle', (shape) ->
2336
x1 = shape.x
@@ -171,7 +184,7 @@ defineSVGRenderer 'Text', (shape) ->
171184
dy = if i == 0 then 0 else '1.2em'
172185
return "
173186
<tspan x='#{shape.x}' dy='#{dy}' alignment-baseline='text-before-edge'>
174-
#{line}
187+
#{escapeHTML(line)}
175188
</tspan>"
176189
).join('')}
177190
</text>

0 commit comments

Comments
 (0)