From 501a9441a5c4dbe544a59d259a9a8e9664886165 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 3 Mar 2022 11:02:16 -0500 Subject: [PATCH] map: Produce 0 instead of NaN for non-numeric string values This has been a problem for...ever, but the old classification system (and calculations) had `||0` for ever variable reference, whereas the new one does not; NaNs result in undefined behavior in the new classification system, since those values are not expected to exist. This ought to have automated tests, but it will be rewritten in TAMER. DEV-10484 --- RELEASES.md | 11 +++++++++++ src/current/compiler/js.xsl | 6 +++--- src/current/compiler/map.xsl | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 1fa20bc5..ab80df3f 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -14,6 +14,17 @@ commits that introduce the changes. To make a new release, run `tools/mkrelease`, which will handle updating the heading for you. +NEXT +==== +This is a bugfix release. + +Compiler +-------- +- Input maps will now ensure that non-numeric string values result in `0` + rather than `NaN`, the latter of which results in undefined behavior in + the new classification system. + + v19.0.0 (2022-03-01) ==================== This version includes a backwards-incomplatible change to enable the new diff --git a/src/current/compiler/js.xsl b/src/current/compiler/js.xsl index 65777141..1e2a9ade 100644 --- a/src/current/compiler/js.xsl +++ b/src/current/compiler/js.xsl @@ -2414,7 +2414,7 @@ { // TODO: error if ( Array.isArray( input ) ) input = input[0]; - return ( input === '' || input === undefined ) ? value : +input; + return ( input === '' || input === undefined ) ? value : +input||0; } // TODO: error for both @@ -2428,9 +2428,9 @@ return input.map( function( x ) { return ( depth === 2 ) ? Array.isArray( x ) - ? x.map( function(s) { return +s; } ) + ? x.map( function(s) { return +s||0; } ) : [ x ] - : ( x === '' || x === undefined ) ? value : +x; + : ( x === '' || x === undefined ) ? value : +x||0; } ); } diff --git a/src/current/compiler/map.xsl b/src/current/compiler/map.xsl index 15acbb74..9a6e5d58 100644 --- a/src/current/compiler/map.xsl +++ b/src/current/compiler/map.xsl @@ -796,7 +796,7 @@ - ''+val[i] + +val[i]||0