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

fix: scientific notation circumvented bounds check #110

Merged
merged 1 commit into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ function parse (args, opts) {

function maybeCoerceNumber (key, value) {
if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.coercions)) {
const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && (Number.isSafeInteger(parseInt(value)))
const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && (
Number.isSafeInteger(Math.floor(value))
)
if (shouldCoerceNumber || (!isUndefined(value) && checkAllAliases(key, flags.numbers))) value = Number(value)
}
return value
Expand Down
5 changes: 5 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,11 @@ describe('yargs-parser', function () {
argv.foo.should.equal('93940495950949399948393')
})

it('does not magically convert scientific notation larger than Number.MAX_SAFE_INTEGER', () => {
const argv = parser([ '--foo', '33e99999' ])
argv.foo.should.equal('33e99999')
})

it('converts numeric options larger than Number.MAX_SAFE_INTEGER to number', () => {
const argv = parser([ '--foo', '93940495950949399948393' ], {
number: ['foo']
Expand Down