fixed when default value in a template attribute is a number and type = number checking fails fixed #130

This commit is contained in:
javi 2014-02-06 17:45:48 +01:00
parent 78f69d5236
commit f5e0d06e2f
2 changed files with 5 additions and 4 deletions

View File

@ -557,7 +557,7 @@ o.instance = function(template, params) {
} }
else if ( type === 'number' ) { else if ( type === 'number' ) {
// check it's a 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 '" throw new Error("Invalid number value for template parameter '"
+ k + "': " + val); + k + "': " + val);
} }

View File

@ -337,6 +337,7 @@ suite('template_maps', function() {
color: { type: "css_color", default: "#a0fF9A" }, color: { type: "css_color", default: "#a0fF9A" },
name: { type: "sql_literal", default: "test" }, name: { type: "sql_literal", default: "test" },
zoom: { type: "number", default: "0" }, zoom: { type: "number", default: "0" },
test_number: { type: "number", default: 23 },
}, },
layergroup: { layergroup: {
version: '1.0.0', version: '1.0.0',
@ -344,7 +345,7 @@ suite('template_maps', function() {
layers: [ layers: [
{ options: { { options: {
sql: "select '<%=name %>' || id, g from t", sql: "select '<%=name %>' || id, g from t",
cartocss: '#layer { marker-fill:<%= fill %>; }' cartocss: '#layer { marker-fill:<%= fill %>; marker-width: <%=test_number %>; }'
} }, } },
{ options: { { options: {
sql: "select fun('<%= name%>') g from x", sql: "select fun('<%= name%>') g from x",
@ -362,7 +363,7 @@ suite('template_maps', function() {
var lyr = inst.layers[0].options; var lyr = inst.layers[0].options;
assert.equal(lyr.sql, "select 'test' || id, g from t"); 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; lyr = inst.layers[1].options;
assert.equal(lyr.sql, "select fun('test') g from x"); assert.equal(lyr.sql, "select fun('test') g from x");
@ -372,7 +373,7 @@ suite('template_maps', function() {
lyr = inst.layers[0].options; lyr = inst.layers[0].options;
assert.equal(lyr.sql, "select 'it''s dangerous' || id, g from t"); 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; lyr = inst.layers[1].options;
assert.equal(lyr.sql, "select fun('it''s dangerous') g from x"); assert.equal(lyr.sql, "select fun('it''s dangerous') g from x");