From 638f2730a6a0017d2a524ef9448f4e105f52bb15 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 10 Oct 2018 14:48:40 -0400 Subject: [PATCH 1/3] tighten validation to disallow expressions as stop values fix #7387 --- src/style-spec/validate/validate_function.js | 8 +++++++- .../style-spec/fixture/functions.input.json | 19 +++++++++++++++++++ .../style-spec/fixture/functions.output.json | 6 +++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/style-spec/validate/validate_function.js b/src/style-spec/validate/validate_function.js index f34303a06dc..a8c88216c06 100644 --- a/src/style-spec/validate/validate_function.js +++ b/src/style-spec/validate/validate_function.js @@ -1,6 +1,7 @@ import ValidationError from '../error/validation_error'; import getType from '../util/get_type'; +import extend from '../util/extend'; import validate from './validate'; import validateObject from './validate_object'; import validateArray from './validate_array'; @@ -138,10 +139,15 @@ export default function validateFunction(options) { }, value)); } + // Remove `expression` from the value spec because expressions + // and functions are not allowed as values within functions. + const stopValueSpec = extend({}, functionValueSpec); + delete stopValueSpec.expression; + return errors.concat(validate({ key: `${key}[1]`, value: value[1], - valueSpec: functionValueSpec, + valueSpec: stopValueSpec, style: options.style, styleSpec: options.styleSpec })); diff --git a/test/unit/style-spec/fixture/functions.input.json b/test/unit/style-spec/fixture/functions.input.json index 82bc2a06e2c..68c63fda0ad 100644 --- a/test/unit/style-spec/fixture/functions.input.json +++ b/test/unit/style-spec/fixture/functions.input.json @@ -967,6 +967,25 @@ "layout": { "line-join": [ "coalesce", ["feature-state", "myState"], "bevel"] } + }, { + "id": "invalid function - expression as stop value", + "type": "line", + "source": "source", + "source-layer": "layer", + "paint": { + "line-width": { + "base": 1, + "stops": [ + [ + 6, + [ + "literal", + 3 + ] + ] + ] + } } + } ] } diff --git a/test/unit/style-spec/fixture/functions.output.json b/test/unit/style-spec/fixture/functions.output.json index c7685c8d7a1..c70c5d9ed8a 100644 --- a/test/unit/style-spec/fixture/functions.output.json +++ b/test/unit/style-spec/fixture/functions.output.json @@ -198,5 +198,9 @@ { "message": "layers[55].layout.line-join: \"feature-state\" data expressions are not supported with layout properties.", "line": 968 + }, + { + "message": "layers[56].paint.line-width.stops[0][1]: number expected, array found", + "line": 981 } -] \ No newline at end of file +] From b3c1330f249d5f3cffc76237192bfbf3f0502631 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 12 Oct 2018 13:12:47 -0400 Subject: [PATCH 2/3] molly's improvement! --- src/style-spec/validate/validate_function.js | 12 ++++++------ test/unit/style-spec/fixture/functions.output.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/style-spec/validate/validate_function.js b/src/style-spec/validate/validate_function.js index a8c88216c06..694ec6e8c12 100644 --- a/src/style-spec/validate/validate_function.js +++ b/src/style-spec/validate/validate_function.js @@ -6,7 +6,8 @@ import validate from './validate'; import validateObject from './validate_object'; import validateArray from './validate_array'; import validateNumber from './validate_number'; -import { unbundle } from '../util/unbundle_jsonlint'; +import { isExpression } from '../expression'; +import { unbundle, deepUnbundle } from '../util/unbundle_jsonlint'; import { supportsPropertyExpression, supportsZoomExpression, @@ -139,15 +140,14 @@ export default function validateFunction(options) { }, value)); } - // Remove `expression` from the value spec because expressions - // and functions are not allowed as values within functions. - const stopValueSpec = extend({}, functionValueSpec); - delete stopValueSpec.expression; + if (isExpression(deepUnbundle(value[1]))) { + return errors.concat([new ValidationError(`${key}[1]`, value[1], 'expressions are not allowed in function stops.')]); + }; return errors.concat(validate({ key: `${key}[1]`, value: value[1], - valueSpec: stopValueSpec, + valueSpec: functionValueSpec, style: options.style, styleSpec: options.styleSpec })); diff --git a/test/unit/style-spec/fixture/functions.output.json b/test/unit/style-spec/fixture/functions.output.json index c70c5d9ed8a..87ec1996fe4 100644 --- a/test/unit/style-spec/fixture/functions.output.json +++ b/test/unit/style-spec/fixture/functions.output.json @@ -200,7 +200,7 @@ "line": 968 }, { - "message": "layers[56].paint.line-width.stops[0][1]: number expected, array found", + "message": "layers[56].paint.line-width.stops[0][1]: expressions are not allowed in function stops.", "line": 981 } ] From 3c44d3bd1da465fb461d34dd0a4c4ecc1082c6ec Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 12 Oct 2018 13:48:30 -0400 Subject: [PATCH 3/3] fixup --- src/style-spec/validate/validate_function.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/style-spec/validate/validate_function.js b/src/style-spec/validate/validate_function.js index 694ec6e8c12..e38ccce1f29 100644 --- a/src/style-spec/validate/validate_function.js +++ b/src/style-spec/validate/validate_function.js @@ -1,7 +1,6 @@ import ValidationError from '../error/validation_error'; import getType from '../util/get_type'; -import extend from '../util/extend'; import validate from './validate'; import validateObject from './validate_object'; import validateArray from './validate_array'; @@ -142,7 +141,7 @@ export default function validateFunction(options) { if (isExpression(deepUnbundle(value[1]))) { return errors.concat([new ValidationError(`${key}[1]`, value[1], 'expressions are not allowed in function stops.')]); - }; + } return errors.concat(validate({ key: `${key}[1]`,