Skip to content

Commit

Permalink
tighten validation to disallow expressions as stop values (#7396)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis authored Oct 12, 2018
1 parent 244104e commit 11b4228
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/style-spec/validate/validate_function.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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,
Expand Down Expand Up @@ -138,6 +139,10 @@ export default function validateFunction(options) {
}, value));
}

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],
Expand Down
19 changes: 19 additions & 0 deletions test/unit/style-spec/fixture/functions.input.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
]
]
}
}
}
]
}
6 changes: 5 additions & 1 deletion test/unit/style-spec/fixture/functions.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]: expressions are not allowed in function stops.",
"line": 981
}
]
]

0 comments on commit 11b4228

Please sign in to comment.