From 018273628d96daae57eb95cb2a85163af04108b8 Mon Sep 17 00:00:00 2001 From: atomcat1978 Date: Tue, 11 Feb 2014 17:25:57 +0100 Subject: [PATCH] Added more advanced special char handling. Added helper method to replace the following special chars to their corresponding special code: &, <, >, " --- svg.export.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/svg.export.js b/svg.export.js index c92e027..52ba7f3 100644 --- a/svg.export.js +++ b/svg.export.js @@ -68,7 +68,7 @@ /* add tspan content */ if (this instanceof SVG.TSpan) - node += whitespaced(this.node.firstChild.nodeValue.replace(/&/g,'&'), options.whitespace, level + 1) + node += whitespaced(_encodeHtmlSpecialChars(this.node.firstChild.nodeValue), options.whitespace, level + 1) /* close node */ node += whitespaced('', options.whitespace, level) @@ -147,5 +147,13 @@ return value; } + + function _encodeHtmlSpecialChars(unsafe) { + return unsafe + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """); + } }).call(this);