Merge pull request #265 from strk/master-quote-amp
Quote ampersend chars in XML text. Closes #263.
This commit is contained in:
commit
435452ba50
@ -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, '<');
|
||||
xmlvalue = xmlvalue.replace(/\>/g, '>');
|
||||
return (quotes === true) ? "'" + xmlvalue + "'" : this.value;
|
||||
},
|
||||
|
||||
|
@ -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>"'");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user