From e37aa5f678eb472c47bc2388bcc8ec71330e1c3e Mon Sep 17 00:00:00 2001 From: mayagao Date: Tue, 22 Dec 2015 14:09:27 -0500 Subject: [PATCH] prevent ramp from having duplicate stops --- lib/validate/parsed.js | 4 ++-- test/fixture/functions.input.json | 20 ++++++++++++++++++++ test/fixture/functions.output.json | 18 +++++++++++------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/validate/parsed.js b/lib/validate/parsed.js index 125d65f..b05db72 100644 --- a/lib/validate/parsed.js +++ b/lib/validate/parsed.js @@ -328,8 +328,8 @@ module.exports = function(style, reference) { error(key + '[0]', val[0], 'zoom level for piecewise-constant functions must be an integer'); } - if (val[0] < lastStop) { - error(key + '[0]', val[0], 'array stops must appear in ascending order'); + if (val[0] <= lastStop) { + error(key + '[0]', val[0], 'array stops must appear in ascending order and have no duplicates'); } lastStop = val[0]; diff --git a/test/fixture/functions.input.json b/test/fixture/functions.input.json index 5f43c8f..1d98626 100644 --- a/test/fixture/functions.input.json +++ b/test/fixture/functions.input.json @@ -125,6 +125,26 @@ } } }, + { + "id": "duplicate-stop", + "type": "line", + "source": "source", + "source-layer": "layer", + "paint": { + "line-width": { + "stops": [ + [ + 1, + 0 + ], + [ + 1, + 0 + ] + ] + } + } + }, { "id": "v6-array-function", "type": "fill", diff --git a/test/fixture/functions.output.json b/test/fixture/functions.output.json index 36e4850..b7940c7 100644 --- a/test/fixture/functions.output.json +++ b/test/fixture/functions.output.json @@ -36,19 +36,23 @@ "line": 102 }, { - "message": "layers[8].paint.line-width.stops[1][0]: array stops must appear in ascending order", + "message": "layers[8].paint.line-width.stops[1][0]: array stops must appear in ascending order and have no duplicates", "line": 121 }, { - "message": "layers[9].paint.fill-translate[0]: number expected, object found", - "line": 135 + "message": "layers[9].paint.line-width.stops[1][0]: array stops must appear in ascending order and have no duplicates", + "line": 141 }, { - "message": "layers[9].paint.fill-translate[1]: number expected, object found", - "line": 139 + "message": "layers[10].paint.fill-translate[0]: number expected, object found", + "line": 155 }, { - "message": "layers[11].paint.fill-antialias.stops[0][0]: zoom level for piecewise-constant functions must be an integer", - "line": 165 + "message": "layers[10].paint.fill-translate[1]: number expected, object found", + "line": 159 + }, + { + "message": "layers[12].paint.fill-antialias.stops[0][0]: zoom level for piecewise-constant functions must be an integer", + "line": 185 } ] \ No newline at end of file