Skip to content

Commit

Permalink
Only check MAX_SAFE_INTEGER for 'match' labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Aug 28, 2017
1 parent cd21590 commit aa451de
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 104 deletions.
5 changes: 0 additions & 5 deletions src/style-spec/function/definitions/curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ class Curve implements Expression {
return context.error('Input/output pairs for "curve" expressions must be defined using literal numeric values (not computed expressions) for the input values.', i + 3);
}


if (Math.abs(label) > Number.MAX_SAFE_INTEGER) {
return context.error(`Numeric values must be no larger than ${Number.MAX_SAFE_INTEGER}.`, i + 3);
}

if (stops.length && stops[stops.length - 1][0] > label) {
return context.error('Input/output pairs for "curve" expressions must be arranged with input values in strictly ascending order.', i + 3);
}
Expand Down
22 changes: 0 additions & 22 deletions src/style-spec/function/definitions/literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class Literal implements Expression {
if (args.length !== 2)
return context.error(`'literal' expression requires exactly one argument, but found ${args.length - 1} instead.`);

if (hasInvalidNumber(args[1], context)) {
return null;
}

if (!isValue(args[1]))
return context.error(`invalid value`);

Expand Down Expand Up @@ -64,22 +60,4 @@ class Literal implements Expression {
accept(visitor: Visitor<Expression>) { visitor.visit(this); }
}

function hasInvalidNumber (value: mixed, context: ParsingContext) {
if (typeof value === 'number' && Math.abs(value) > Number.MAX_SAFE_INTEGER) {
context.error(`Numeric values must be no larger than ${Number.MAX_SAFE_INTEGER}.`);
return true;
} else if (Array.isArray(value)) {
return value.some(item => hasInvalidNumber(item, context));
} else if (value && typeof value === 'object') {
for (const key in value) {
if (hasInvalidNumber(value[key], context)) {
return true;
}
}
}

return false;
}


module.exports = Literal;
2 changes: 1 addition & 1 deletion src/style-spec/function/definitions/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Match implements Expression {
if (typeof label !== 'number' && typeof label !== 'string') {
return labelContext.error(`Branch labels must be numbers or strings.`);
} else if (typeof label === 'number' && Math.abs(label) > Number.MAX_SAFE_INTEGER) {
return labelContext.error(`Numeric values must be no larger than ${Number.MAX_SAFE_INTEGER}.`);
return labelContext.error(`Branch labels must be integers no larger than ${Number.MAX_SAFE_INTEGER}.`);

} else if (typeof label === 'number' && Math.floor(label) !== label) {
return labelContext.error(`Numeric branch labels must be integer values.`);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"errors": [
{
"key": "[2]",
"error": "Numeric values must be no larger than 9007199254740991."
"error": "Branch labels must be integers no larger than 9007199254740991."
}
]
}
Expand Down

0 comments on commit aa451de

Please sign in to comment.