diff --git a/editor/svgutils.js b/editor/svgutils.js index 1a1bcd49..48876a35 100644 --- a/editor/svgutils.js +++ b/editor/svgutils.js @@ -55,7 +55,9 @@ svgedit.utilities.init = function(editorContext) { // Returns: // The converted string svgedit.utilities.toXml = function(str) { - return $('
').text(str).html(); + // ' is ok in XML, but not HTML + // > does not normally need escaping, though it can if within a CDATA expression (and preceded by "]]") + return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/, '''); }; // Function: svgedit.utilities.fromXml diff --git a/test/svgutils_test.html b/test/svgutils_test.html index 73ff5ba5..0063ba03 100644 --- a/test/svgutils_test.html +++ b/test/svgutils_test.html @@ -41,7 +41,7 @@ equals(toXml('PB&J'), 'PB&J'); equals(toXml('2 < 5'), '2 < 5'); equals(toXml('5 > 2'), '5 > 2'); - equals(toXml('\'<&>"'), '\'<&>"'); + equals(toXml('\'<&>"'), ''<&>"'); }); test('Test svgedit.utilities.fromXml() function', function() {