Fix escaping of single quote. Closes #307, updates tests.
This commit is contained in:
parent
761b05b599
commit
fa994557e8
@ -7,8 +7,12 @@ tree.Quoted = function Quoted(content) {
|
||||
|
||||
tree.Quoted.prototype = {
|
||||
toString: function(quotes) {
|
||||
var xmlvalue = this.value.replace(/&/g, '&');
|
||||
xmlvalue = xmlvalue.replace(/\'/g, ''');
|
||||
var xmlvalue = this.value
|
||||
.replace(/&/g, '&')
|
||||
.replace(/\'/g, '\\\'')
|
||||
.replace(/\"/g, '"')
|
||||
.replace(/</g, '<')
|
||||
.replace(/\>/g, '>');
|
||||
return (quotes === true) ? "'" + xmlvalue + "'" : this.value;
|
||||
},
|
||||
|
||||
|
23
test/quoted.test.js
Normal file
23
test/quoted.test.js
Normal file
@ -0,0 +1,23 @@
|
||||
var assert = require('assert');
|
||||
var tree = require('../lib/carto/tree.js');
|
||||
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>\"");
|
||||
assert.ok(f);
|
||||
assert.equal(f.is, 'string');
|
||||
});
|
||||
it('should produce normal output', function() {
|
||||
var f = new tree.Quoted("Tom's & \"<quoted>\"");
|
||||
assert.ok(f);
|
||||
assert.equal(f.toString(), "Tom's & \"<quoted>\"");
|
||||
});
|
||||
it('should produce xml-friendly output', function() {
|
||||
var f = new tree.Quoted("Tom's & \"<quoted>\"");
|
||||
assert.ok(f);
|
||||
assert.equal(f.toString(true), "'Tom\\'s & "<quoted>"'");
|
||||
});
|
||||
});
|
||||
});
|
@ -5,7 +5,7 @@
|
||||
|
||||
<Style name="world" filter-mode="first">
|
||||
<Rule>
|
||||
<Filter>([name2] = ' Sa'ad')</Filter>
|
||||
<Filter>([name2] = ' Sa\'ad')</Filter>
|
||||
<PolygonSymbolizer fill="#ffffff" />
|
||||
</Rule>
|
||||
</Style>
|
||||
|
Loading…
Reference in New Issue
Block a user