diff --git a/CHANGELOG.md b/CHANGELOG.md index 19467b7d..a4f10ffe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ + ### Bugfixes - Moves `_comment` blocks in airport json file to be within object the are describing [#145](https://github.com/n8rzz/atc/issues/145) - Streamlines flight number generation and adds new method to add new callsigns to the existing list [#151](https://github.com/n8rzz/atc/issues/151) @@ -74,3 +75,5 @@ - Aircraft strips show arrival airport in uppercase [#108](https://github.com/n8rzz/atc/issues/108) - Updates `FixCollection.findFixByName()` to accept upper, mixed, or lower case fix name [#109](https://github.com/n8rzz/atc/issues/109) - Switching to a previously loaded airport does not clear previous airport fixes [#115](https://github.com/n8rzz/atc/issues/115) +- Fixes `parseElevation()` so that it does not return NaN when it is given the string `'Infinity'` [#191] (https://github.com/n8rzz/atc/issues/191) + - Originally reported under [#756](https://github.com/zlsa/atc/issues/756) \ No newline at end of file diff --git a/src/assets/scripts/utilities/unitConverters.js b/src/assets/scripts/utilities/unitConverters.js index e8b3a2ba..a38b2998 100644 --- a/src/assets/scripts/utilities/unitConverters.js +++ b/src/assets/scripts/utilities/unitConverters.js @@ -301,7 +301,9 @@ export const parseElevation = (elevation) => { // if its a number, we're done here. // This will catch whole numbers, floats, Infinity and -Infinity. - if (_isNumber(elevation)) { + // This checks if strings are given will skip the regex and exit early + // Also stops the function from returning NaN + if (_isNumber(elevation) || elevation === 'Infinity' || elevation === '-Infinity') { return parseFloat(elevation); } @@ -320,3 +322,4 @@ export const parseElevation = (elevation) => { return parseFloat(parsedElevation); }; + diff --git a/test/utilities/unitConverters.spec.js b/test/utilities/unitConverters.spec.js index e26a75e1..d0f2883b 100644 --- a/test/utilities/unitConverters.spec.js +++ b/test/utilities/unitConverters.spec.js @@ -129,4 +129,6 @@ ava('.parseElevation() should parse a string elevation into an elevation in feet t.true(parseElevation('-23m') === -75.45931758530183); t.true(parseElevation(Infinity) === Infinity); t.true(parseElevation(-Infinity) === -Infinity); + t.true(parseElevation('Infinity') === Infinity); + t.true(parseElevation('-Infinity') === -Infinity); });