From fd94fbd2e69ce2e338929f07aa0d94cf263eb19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 6 Mar 2017 11:57:07 +0100 Subject: [PATCH] Support numbers for '=~' operator --- lib/carto/tree/filterset.js | 2 +- test/rendering_js.test.js | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/carto/tree/filterset.js b/lib/carto/tree/filterset.js index 168816f..2866959 100644 --- a/lib/carto/tree/filterset.js +++ b/lib/carto/tree/filterset.js @@ -93,7 +93,7 @@ tree.Filterset.prototype.toJS = function(env) { } var attrs = "data"; 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); }).join(' && '); diff --git a/test/rendering_js.test.js b/test/rendering_js.test.js index e546a3b..f68cfe8 100644 --- a/test/rendering_js.test.js +++ b/test/rendering_js.test.js @@ -196,10 +196,10 @@ describe('RenderingJS', function() { var value = layer.shader['marker-width'].style({ name: 'wadus' }, { zoom: 1 }); }); }); - - it("should not throw `TypeError` if left operand is not a `string` with operator `=~`", function(){ + + it("`=~` operator should support numbers", function(){ var css = [ - '#layer[name=~".*wadus*"] {', + '#layer[value=~"^10"] {', ' marker-width: 14;', '}' ].join('\n'); @@ -207,10 +207,7 @@ describe('RenderingJS', function() { assert.doesNotThrow(function () { var shader = (new carto.RendererJS({})).render(css); var layer = shader.getLayers()[0]; - var value = layer.shader['marker-width'].style({ name: 1 }, { zoom: 1 }); - value = layer.shader['marker-width'].style({ name: null }, { zoom: 1 }); - value = layer.shader['marker-width'].style({ name: undefined }, { zoom: 1 }); - value = layer.shader['marker-width'].style({ name: true }, { zoom: 1 }); - }); + var value = layer.shader['marker-width'].style({ value: 10 }, { zoom: 1 }); + }, Error); }); });