escape XML in SVG strings

This commit is contained in:
Tim de Koning 2012-02-09 09:54:30 +01:00
parent e5d92f71d5
commit 0ed5f80248
2 changed files with 16 additions and 4 deletions

View file

@ -328,7 +328,7 @@
toFixed(lineTopOffset + (i === 0 ? this._shadowOffsets[j][1] : 0), 2),
'" ',
this._getFillAttributes(this._shadows[j].color), '>',
textLines[i],
fabric.util.string.escapeXml(textLines[i]),
'</tspan>');
lineTopOffsetMultiplier = 1;
} else {
@ -355,7 +355,7 @@
toFixed(lineTopOffset * lineTopOffsetMultiplier, 2) , '" ',
// doing this on <tspan> elements since setting opacity on containing <text> one doesn't work in Illustrator
this._getFillAttributes(this.fill), '>',
textLines[i],
fabric.util.string.escapeXml(textLines[i]),
'</tspan>'
);
lineTopOffsetMultiplier = 1;

View file

@ -1,3 +1,5 @@
(function() {
if (!String.prototype.trim) {
/**
* Trims a string (removing whitespace from the beginning and the end)
@ -34,8 +36,18 @@ function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
function escapeXml(string) {
return string.replace('&', '&amp;')
.replace('"', '&quot;')
.replace("'", '&apos;')
.replace("<", '&lt;')
.replace(">", '&gt;');
}
/** @namespace */
fabric.util.string = {
camelize: camelize,
capitalize: capitalize
};
capitalize: capitalize,
escapeXml: escapeXml
};
}());