Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseValues fails on long numbers #298

Open
mlarcher opened this issue Mar 22, 2018 · 1 comment
Open

parseValues fails on long numbers #298

mlarcher opened this issue Mar 22, 2018 · 1 comment

Comments

@mlarcher
Copy link

mlarcher commented Mar 22, 2018

The parseValues option of .env method doesn't return the expected value on long numbers (greater than Number.MAX_SAFE_INTEGER).
For example, '123456123456123456', will return 123456123456123460.
This is due to javascript handling and not nconf.

To prevent this kind of problems, wouldn't it be a good thing to make sure that a numeric like env variable can be cast back to its original string value ?
i.e. in

val = JSON.parse(value);

do something like:

common.parseValues = function (value) {
  var val = value;
  
  try {
    const castValue = JSON.parse(value);
    if (JSON.stringify(castValue) !== value) {
      throw "ignored";
    }
    val = castValue;
  } catch (ignore) {
    // Check for any other well-known strings that should be "parsed"
    if (value === 'undefined'){
      val = void 0;
    }
  }

  return val;
};

What do you think ?

@mhamann
Copy link
Collaborator

mhamann commented Mar 22, 2018

Looks like a decent proposal. Submit a PR with tests ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants