From a1dca3c32e5438856b68dad07fa81c8332807a81 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 12 Sep 2018 10:32:01 -0700 Subject: [PATCH] Make "to-number" of null behave as documented --- src/style-spec/expression/definitions/coercion.js | 2 +- test/integration/expression-tests/to-number/2-ary/test.json | 6 +++--- test/integration/expression-tests/to-number/basic/test.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/style-spec/expression/definitions/coercion.js b/src/style-spec/expression/definitions/coercion.js index d459a5da6fc..e48ea2192b4 100644 --- a/src/style-spec/expression/definitions/coercion.js +++ b/src/style-spec/expression/definitions/coercion.js @@ -90,7 +90,7 @@ class Coercion implements Expression { let value = null; for (const arg of this.args) { value = arg.evaluate(ctx); - if (value === null) continue; + if (value === null) return 0; const num = Number(value); if (isNaN(num)) continue; return num; diff --git a/test/integration/expression-tests/to-number/2-ary/test.json b/test/integration/expression-tests/to-number/2-ary/test.json index 9806be5a092..bbed5b9cbab 100644 --- a/test/integration/expression-tests/to-number/2-ary/test.json +++ b/test/integration/expression-tests/to-number/2-ary/test.json @@ -23,11 +23,11 @@ 1, 6.02e-23, -1, + 0, -1, -1, - -1, - -1, - {"error": "Could not convert \"bad fallback\" to number."} + 0, + 0 ], "serialized": ["to-number", ["get", "x"], ["get", "y"]] } diff --git a/test/integration/expression-tests/to-number/basic/test.json b/test/integration/expression-tests/to-number/basic/test.json index b0c13c11805..1d769c89f0d 100644 --- a/test/integration/expression-tests/to-number/basic/test.json +++ b/test/integration/expression-tests/to-number/basic/test.json @@ -21,7 +21,7 @@ 1, 6.02e-23, {"error": "Could not convert \"Not a number\" to number."}, - {"error": "Could not convert null to number."}, + 0, {"error": "Could not convert [1,2] to number."}, {"error": "Could not convert {\"y\":1} to number."} ],