From c5a67fa938bc18001dabb80821eb4530cd4883dc Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 25 Feb 2013 09:17:56 -0500 Subject: [PATCH] Missing bracket. Refs #254 --- lib/carto/parser.js | 7 ++++++- test/errorhandling/missing_close.mml | 14 ++++++++++++++ test/errorhandling/missing_close.mss | 4 ++++ test/errorhandling/missing_close.result | 11 +++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/errorhandling/missing_close.mml create mode 100644 test/errorhandling/missing_close.mss create mode 100644 test/errorhandling/missing_close.result diff --git a/lib/carto/parser.js b/lib/carto/parser.js index 316442f..42ede43 100644 --- a/lib/carto/parser.js +++ b/lib/carto/parser.js @@ -575,7 +575,12 @@ carto.Parser = function Parser(env) { $(this.entities.dimension) || $(this.entities.keyword) || $(this.entities.field))) { - if (! $(']')) return; + if (! $(']')) { + throw makeError({ + message: 'Missing closing ] of filter.', + index: memo - 1 + }); + } if (!key.is) key = new tree.Field(key); return new tree.Filter(key, op, val, memo, env.filename); } diff --git a/test/errorhandling/missing_close.mml b/test/errorhandling/missing_close.mml new file mode 100644 index 0000000..4dee5ed --- /dev/null +++ b/test/errorhandling/missing_close.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": [ + "missing_close.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/errorhandling/missing_close.mss b/test/errorhandling/missing_close.mss new file mode 100644 index 0000000..9f2efe1 --- /dev/null +++ b/test/errorhandling/missing_close.mss @@ -0,0 +1,4 @@ +#world[natural="water" +{ + polygon-fill: blue; +} diff --git a/test/errorhandling/missing_close.result b/test/errorhandling/missing_close.result new file mode 100644 index 0000000..2536935 --- /dev/null +++ b/test/errorhandling/missing_close.result @@ -0,0 +1,11 @@ +Error: missing_close.mss:1:5 Missing closing ] of filter. + at makeError (/Users/tmcw/src/carto/lib/carto/parser.js:131:16) + at Object.carto.Parser.parser.parsers.filter (/Users/tmcw/src/carto/lib/carto/parser.js:579:35) + at $ (/Users/tmcw/src/carto/lib/carto/parser.js:50:24) + at Object.carto.Parser.parser.parsers.selector (/Users/tmcw/src/carto/lib/carto/parser.js:523:30) + at $ (/Users/tmcw/src/carto/lib/carto/parser.js:50:24) + at Object.carto.Parser.parser.parsers.ruleset (/Users/tmcw/src/carto/lib/carto/parser.js:615:28) + at $ (/Users/tmcw/src/carto/lib/carto/parser.js:50:24) + at Object.carto.Parser.parser.parsers.primary (/Users/tmcw/src/carto/lib/carto/parser.js:297:48) + at $ (/Users/tmcw/src/carto/lib/carto/parser.js:50:24) + at Object.carto.Parser.parser.parse (/Users/tmcw/src/carto/lib/carto/parser.js:227:41)