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

Fix off-by-one error in array expression error message #6269

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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: 6 additions & 2 deletions src/style-spec/expression/definitions/at.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ class At implements Expression {
const index = ((this.index.evaluate(ctx): any): number);
const array = ((this.input.evaluate(ctx): any): Array<Value>);

if (index < 0 || index >= array.length) {
throw new RuntimeError(`Array index out of bounds: ${index} > ${array.length}.`);
if (index < 0) {
throw new RuntimeError(`Array index out of bounds: ${index} < 0.`);
}

if (index >= array.length) {
throw new RuntimeError(`Array index out of bounds: ${index} > ${array.length - 1}.`);
}

if (index !== Math.floor(index)) {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/expression-tests/at/basic/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
"outputs": [
8,
{"error": "Array index out of bounds: -1 > 3."},
{"error": "Array index out of bounds: 4 > 3."},
{"error": "Array index out of bounds: -1 < 0."},
{"error": "Array index out of bounds: 4 > 2."},
{"error": "Array index must be an integer, but found 1.5 instead."}
],
"serialized": [
Expand Down