Raphael.Export icon indicating copy to clipboard operation
Raphael.Export copied to clipboard

Escaping of text elements

Open git-afsantos opened this issue 11 years ago • 2 comments

Text elements that include special charaters are being incorrectly exported. For instance, when I have text elements with the text <trigger>, the generated SVG is

<text transform="matrix(1,0,0,1,0,0)" style="text-anchor: end; font: normal normal normal 10px/normal Arial;" x="161" y="31.5" text-anchor="end" font="10px &quot;Arial&quot;" stroke="none" fill="#000"><tspan dy="3.634615384615385"><trigger></tspan></text>

That <trigger> tag is parsed as a regular SVG tag, and isn't displayed in the resulting SVG image.

In the 'text' serializer, line 209, I've replaced

tags.push(tag(
    'text',
    attrs,
    node.matrix,
    tag('tspan', {
        dy: computeTSpanDy(style.font.size, line + 1, totalLines)
    }, null, text.replace(/&/g, "&amp;"))
));

with

tags.push(tag(
    'text',
    attrs,
    node.matrix,
    tag('tspan', {
        dy: computeTSpanDy(style.font.size, line + 1, totalLines)
    }, null, escapeXML(text.replace(/&/g, "&amp;")))
));

and that seems to do the trick, thus far.

git-afsantos avatar Jul 28 '14 14:07 git-afsantos

Presumably, the correct fix would be to update escapeXML() to encode ampersands properly.

MarkMaldaba avatar Feb 20 '18 15:02 MarkMaldaba

This is hopefully fixed by PR #54.

MarkMaldaba avatar Mar 07 '18 12:03 MarkMaldaba