Support numbers for '=~' operator

This commit is contained in:
Daniel García Aubert 2017-03-06 11:57:07 +01:00
parent 5c4bed9593
commit fd94fbd2e6
2 changed files with 6 additions and 9 deletions

View File

@ -93,7 +93,7 @@ tree.Filterset.prototype.toJS = function(env) {
} }
var attrs = "data"; var attrs = "data";
if (op === '=~') { if (op === '=~') {
return "(typeof " + attrs + "['" + filter.key.value + "'] === 'string') && " + attrs + "['" + filter.key.value + "'].match(" + (val.is === 'string' ? "'" + val.toString().replace(/'/g, "\\'") + "'" : val) + ")"; return "(" + attrs + "['" + filter.key.value + "'] + '').match(" + (val.is === 'string' ? "'" + val.toString().replace(/'/g, "\\'") + "'" : val) + ")";
} }
return attrs + "['" + filter.key.value + "'] " + op + " " + (val.is === 'string' ? "'" + val.toString().replace(/'/g, "\\'") + "'" : val); return attrs + "['" + filter.key.value + "'] " + op + " " + (val.is === 'string' ? "'" + val.toString().replace(/'/g, "\\'") + "'" : val);
}).join(' && '); }).join(' && ');

View File

@ -197,9 +197,9 @@ describe('RenderingJS', function() {
}); });
}); });
it("should not throw `TypeError` if left operand is not a `string` with operator `=~`", function(){ it("`=~` operator should support numbers", function(){
var css = [ var css = [
'#layer[name=~".*wadus*"] {', '#layer[value=~"^10"] {',
' marker-width: 14;', ' marker-width: 14;',
'}' '}'
].join('\n'); ].join('\n');
@ -207,10 +207,7 @@ describe('RenderingJS', function() {
assert.doesNotThrow(function () { assert.doesNotThrow(function () {
var shader = (new carto.RendererJS({})).render(css); var shader = (new carto.RendererJS({})).render(css);
var layer = shader.getLayers()[0]; var layer = shader.getLayers()[0];
var value = layer.shader['marker-width'].style({ name: 1 }, { zoom: 1 }); var value = layer.shader['marker-width'].style({ value: 10 }, { zoom: 1 });
value = layer.shader['marker-width'].style({ name: null }, { zoom: 1 }); }, Error);
value = layer.shader['marker-width'].style({ name: undefined }, { zoom: 1 });
value = layer.shader['marker-width'].style({ name: true }, { zoom: 1 });
});
}); });
}); });