From 1d9b5d93ca94201df1f3095a9c8dc43339182162 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 8 Oct 2012 18:28:27 -0400 Subject: [PATCH] Permit keywords as strings. Fixes #193 --- lib/carto/tree/reference.js | 14 +++++++++++--- test/rendering/noquote_font.mml | 14 ++++++++++++++ test/rendering/noquote_font.mss | 4 ++++ test/rendering/noquote_font.result | 20 ++++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 test/rendering/noquote_font.mml create mode 100644 test/rendering/noquote_font.mss create mode 100644 test/rendering/noquote_font.result diff --git a/lib/carto/tree/reference.js b/lib/carto/tree/reference.js index a033dcb..d1c03ad 100644 --- a/lib/carto/tree/reference.js +++ b/lib/carto/tree/reference.js @@ -136,9 +136,17 @@ tree.Reference.validValue = function(env, selector, value) { if (!tree.Reference.selector(selector)) { return false; } else if (value.value[0].is == 'keyword') { - return tree.Reference - .selector(selector).type - .indexOf(value.value[0].value) !== -1; + if (typeof tree.Reference.selector(selector).type === 'object') { + return tree.Reference + .selector(selector).type + .indexOf(value.value[0].value) !== -1; + // Lax permissions for single strings. If you provide a keyword + // aka unquoted string to a property that is a string, it'll be fine. + } else if (tree.Reference.selector(selector).type === 'string') { + return true; + } else { + return false; + } } else if (value.value[0].is == 'undefined') { // caught earlier in the chain - ignore here so that // error is not overridden diff --git a/test/rendering/noquote_font.mml b/test/rendering/noquote_font.mml new file mode 100644 index 0000000..d76e744 --- /dev/null +++ b/test/rendering/noquote_font.mml @@ -0,0 +1,14 @@ +{ + "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over", + "Stylesheet": [ + "noquote_font.mss" + ], + "Layer": [{ + "name": "world", + "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over", + "Datasource": { + "file": "http://tilemill-data.s3.amazonaws.com/test_data/shape_demo.zip", + "type": "shape" + } + }] +} diff --git a/test/rendering/noquote_font.mss b/test/rendering/noquote_font.mss new file mode 100644 index 0000000..fda7d8d --- /dev/null +++ b/test/rendering/noquote_font.mss @@ -0,0 +1,4 @@ +#world { + text-name: 'foo'; + text-face-name: Helvetica; +} diff --git a/test/rendering/noquote_font.result b/test/rendering/noquote_font.result new file mode 100644 index 0000000..a52023a --- /dev/null +++ b/test/rendering/noquote_font.result @@ -0,0 +1,20 @@ + + + + + + + + world + + + + + + +