Fix issue 1174 reported by psh.tnt re: XML entity escaping (within attributes); updated test as well

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2696 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Brett Zamir 2014-02-12 10:10:56 +00:00
parent d6cc464ba5
commit f18cdbbeae
2 changed files with 4 additions and 2 deletions

View File

@ -55,7 +55,9 @@ svgedit.utilities.init = function(editorContext) {
// Returns:
// The converted string
svgedit.utilities.toXml = function(str) {
return $('<p/>').text(str).html();
// &apos; is ok in XML, but not HTML
// &gt; does not normally need escaping, though it can if within a CDATA expression (and preceded by "]]")
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/, '&#x27;');
};
// Function: svgedit.utilities.fromXml

View File

@ -41,7 +41,7 @@
equals(toXml('PB&J'), 'PB&amp;J');
equals(toXml('2 < 5'), '2 &lt; 5');
equals(toXml('5 > 2'), '5 &gt; 2');
equals(toXml('\'<&>"'), '\'&lt;&amp;&gt;"');
equals(toXml('\'<&>"'), '&#x27;&lt;&amp;&gt;&quot;');
});
test('Test svgedit.utilities.fromXml() function', function() {