Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tighten validation to disallow expressions as stop values #7396

Merged
merged 3 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/style-spec/validate/validate_function.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import ValidationError from '../error/validation_error';
import getType from '../util/get_type';
import extend from '../util/extend';
ansis marked this conversation as resolved.
Show resolved Hide resolved
import validate from './validate';
import validateObject from './validate_object';
import validateArray from './validate_array';
Expand Down Expand Up @@ -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
}));
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]: number expected, array found",
"line": 981
}
]
]