From f5e0d06e2f7b7beec5d8b31c7c55e4355bec30f5 Mon Sep 17 00:00:00 2001 From: javi Date: Thu, 6 Feb 2014 17:45:48 +0100 Subject: [PATCH] fixed when default value in a template attribute is a number and type = number checking fails fixed #130 --- lib/cartodb/template_maps.js | 2 +- test/unit/cartodb/template_maps.test.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/cartodb/template_maps.js b/lib/cartodb/template_maps.js index d29c15f0..d067632b 100644 --- a/lib/cartodb/template_maps.js +++ b/lib/cartodb/template_maps.js @@ -557,7 +557,7 @@ o.instance = function(template, params) { } else if ( type === 'number' ) { // check it's a number - if ( ! val.match(this._reNumber) ) { + if ( typeof(val) !== 'number' && ! val.match(this._reNumber) ) { throw new Error("Invalid number value for template parameter '" + k + "': " + val); } diff --git a/test/unit/cartodb/template_maps.test.js b/test/unit/cartodb/template_maps.test.js index 42b81cf0..4ef04ed4 100644 --- a/test/unit/cartodb/template_maps.test.js +++ b/test/unit/cartodb/template_maps.test.js @@ -337,6 +337,7 @@ suite('template_maps', function() { color: { type: "css_color", default: "#a0fF9A" }, name: { type: "sql_literal", default: "test" }, zoom: { type: "number", default: "0" }, + test_number: { type: "number", default: 23 }, }, layergroup: { version: '1.0.0', @@ -344,7 +345,7 @@ suite('template_maps', function() { layers: [ { options: { sql: "select '<%=name %>' || id, g from t", - cartocss: '#layer { marker-fill:<%= fill %>; }' + cartocss: '#layer { marker-fill:<%= fill %>; marker-width: <%=test_number %>; }' } }, { options: { sql: "select fun('<%= name%>') g from x", @@ -362,7 +363,7 @@ suite('template_maps', function() { var lyr = inst.layers[0].options; assert.equal(lyr.sql, "select 'test' || id, g from t"); - assert.equal(lyr.cartocss, '#layer { marker-fill:red; }'); + assert.equal(lyr.cartocss, '#layer { marker-fill:red; marker-width: 23; }'); lyr = inst.layers[1].options; assert.equal(lyr.sql, "select fun('test') g from x"); @@ -372,7 +373,7 @@ suite('template_maps', function() { lyr = inst.layers[0].options; assert.equal(lyr.sql, "select 'it''s dangerous' || id, g from t"); - assert.equal(lyr.cartocss, '#layer { marker-fill:red; }'); + assert.equal(lyr.cartocss, '#layer { marker-fill:red; marker-width: 23; }'); lyr = inst.layers[1].options; assert.equal(lyr.sql, "select fun('it''s dangerous') g from x");