Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Quote all needed XML chars. See #263.

Includes testcase.
  • Loading branch information...
commit d6585d3691a0c22eaf71b7903abb8082e04f26fd 1 parent acf94e5
@strk authored
Showing with 8 additions and 5 deletions.
  1. +3 −0  lib/carto/tree/quoted.js
  2. +5 −5 test/quoted.test.js
View
3  lib/carto/tree/quoted.js
@@ -10,6 +10,9 @@ tree.Quoted.prototype = {
toString: function(quotes) {
var xmlvalue = this.value.replace(/&/g, '&');
xmlvalue = xmlvalue.replace(/\'/g, ''');
+ xmlvalue = xmlvalue.replace(/\"/g, '"');
+ xmlvalue = xmlvalue.replace(/\</g, '&lt;');
+ xmlvalue = xmlvalue.replace(/\>/g, '&gt;');
return (quotes === true) ? "'" + xmlvalue + "'" : this.value;
},
View
10 test/quoted.test.js
@@ -5,19 +5,19 @@ require('../lib/carto/tree/quoted');
describe('Quoted', function() {
describe('basic functionality', function() {
it('should be constructed', function() {
- var f = new tree.Quoted("Tom's & quoted");
+ var f = new tree.Quoted("Tom's & \"<quoted>\"");
assert.ok(f);
assert.equal(f.is, 'string');
});
it('should produce normal output', function() {
- var f = new tree.Quoted("Tom's & quoted");
+ var f = new tree.Quoted("Tom's & \"<quoted>\"");
assert.ok(f);
- assert.equal(f.toString(), "Tom's & quoted");
+ assert.equal(f.toString(), "Tom's & \"<quoted>\"");
});
it('should produce xml-friendly output', function() {
- var f = new tree.Quoted("Tom's & quoted");
+ var f = new tree.Quoted("Tom's & \"<quoted>\"");
assert.ok(f);
- assert.equal(f.toString(true), "'Tom&apos;s &amp; quoted'");
+ assert.equal(f.toString(true), "'Tom&apos;s &amp; &quot;&lt;quoted&gt;&quot;'");
});
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.