diff --git a/NEWS.md b/NEWS.md index a7831334..3ac726c5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,10 @@ Enhancements: * Allow specifying fixed sqlapi host address (#117) +Bug fixes: + * Template variables with spaces are not replaced correctly (#129) + + 1.6.3 -- 2014-01-30 ------------------- diff --git a/lib/cartodb/template_maps.js b/lib/cartodb/template_maps.js index 76f782c9..d29c15f0 100644 --- a/lib/cartodb/template_maps.js +++ b/lib/cartodb/template_maps.js @@ -534,7 +534,7 @@ o._replaceVars = function(str, params) { if ( ! params._re ) { params._re = {}; for (var k in params) { - params._re[k] = RegExp("<%= " + k + " %>", "g"); + params._re[k] = RegExp("<%=\\s*" + k + "\\s*%>", "g"); } } for (var k in params) str = str.replace(params._re[k], params[k]); diff --git a/test/unit/cartodb/template_maps.test.js b/test/unit/cartodb/template_maps.test.js index 9bc26c48..42b81cf0 100644 --- a/test/unit/cartodb/template_maps.test.js +++ b/test/unit/cartodb/template_maps.test.js @@ -343,11 +343,11 @@ suite('template_maps', function() { global_cartocss_version: '2.0.2', layers: [ { options: { - sql: "select '<%= name %>' || id, g from t", + sql: "select '<%=name %>' || id, g from t", cartocss: '#layer { marker-fill:<%= fill %>; }' } }, { options: { - sql: "select fun('<%= name %>') g from x", + sql: "select fun('<%= name%>') g from x", cartocss: '#layer { line-color:<%= color %>; marker-fill:<%= color %>; }' } }, { options: {