Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #265 from strk/master-quote-amp

Quote ampersend chars in XML text. Closes #263.
  • Loading branch information...
commit 435452ba50188da8fcfd6b2b619e3323dd6856c6 2 parents 5d626d3 + d6585d3
@tmcw tmcw authored
Showing with 10 additions and 6 deletions.
  1. +5 −1 lib/carto/tree/quoted.js
  2. +5 −5 test/quoted.test.js
View
6 lib/carto/tree/quoted.js
@@ -8,7 +8,11 @@ tree.Quoted.prototype = {
is: 'string',
toString: function(quotes) {
- var xmlvalue = this.value.replace(/\'/g, ''');
+ 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 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.