globalizationjquery-globalizationjquery-globalizejavascript-globalize

Globalize bug in new v1.2.*? Parsing empty string returns 0


This question represents a proposed bug for Globalize. The owners of that project ask that it first be published as a SO question, so here we go...

With the new version 1.2.1 (and 1.2.2) of Globalize we're noticing that number-parsing an empty string returns 0 (seemingly independent of culture). This behavior is different to the previous version 1.1.2, where it returned NaN. Reproduction:

var g = new Globalize("en-US");
g.numberParser()(''); // returns 0 in v1.2.1 and NaN in v1.1.2.

Intuition tells me that parsing an empty string should not return 0. Vanilla JavaScript parse functions (e.g. parseInt) return NaN in such cases, supporting this intuition.

Furthermore, the relevant unit test in the Globalize project does not seem to cover this case, so it's unclear whether or not the changed behavior is intended. From a brief look at the changelog of the 1.2.* releases I can't seem to find any note of an intention to change this behavior.

Note that parsing whitespace in the new version does indeed return NaN:

var g = new Globalize("en-US");
g.numberParser()(' '); // returns NaN in both v1.2.1 and v1.1.2.

We're hoping that one of the project members will either confirm that this is a bug and raise a corresponding issue in the Globalize project, or explain why this is now expected behavior.


Solution

  • It's a bug, thanks for reporting, will be tracked in https://github.com/globalizejs/globalize/issues/682