Skip to content
Browse files

Quote ampersend chars in XML text. Closes #263.

Includes testcase.
  • Loading branch information...
1 parent 60661b6 commit acf94e5fab7ef586a3725bf15594c93ad9704f3f @strk committed Mar 22, 2013
Showing with 7 additions and 6 deletions.
  1. +2 −1 lib/carto/tree/quoted.js
  2. +5 −5 test/quoted.test.js
View
3 lib/carto/tree/quoted.js
@@ -8,7 +8,8 @@ tree.Quoted.prototype = {
is: 'string',
toString: function(quotes) {
- var xmlvalue = this.value.replace(/\'/g, ''');
+ var xmlvalue = this.value.replace(/&/g, '&');
+ xmlvalue = xmlvalue.replace(/\'/g, ''');
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's quoted'");
+ assert.equal(f.toString(true), "'Tom's & quoted'");
});
});
});

0 comments on commit acf94e5

Please sign in to comment.
Something went wrong with that request. Please try again.