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

[Bug]: allocate() does not throw when given numeric strings as input #588

Open
2 tasks done
classic0 opened this issue Feb 16, 2022 · 3 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working good first issue Good for newcomers v1 This concerns v1

Comments

@classic0
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

First off, thanks for the great library.

.allocate() function has unexpected behaviour when given falsy input.

Expected behavior

I expected an error:
TypeError: You must provide a non-empty array of numeric values greater than 0

Steps to reproduce

try {
    Dinero({ amount: 100 })
    .allocate([ '2', '98' ])
} catch (error) {
    console.log(error)
}

It never finishes nor throws meanwhile hogging memory.

The same for this:
.allocate([ 1, '98' ])

But this one yields the expected TypeError:
.allocate([ 'a', '98' ])

Version

1.9.1

Environment

14.17.3

Code of Conduct

  • I agree to follow this project's Code of Conduct
@classic0 classic0 added the bug Something isn't working label Feb 16, 2022
@sarahdayan
Copy link
Collaborator

Hey @classic0, this seems like a v1 bug indeed, the function should either convert the input, or throw. In the meantime, I'd recommend making sure you feed Dinero.js with numbers only (using Number or parseInt on your inputs).

I'm not actively maintaining v1 but I do review PRs, so feel free to check the v1 branch if you want to take a stab at it.

@sarahdayan sarahdayan added good first issue Good for newcomers v1 This concerns v1 labels Mar 20, 2022
@matheusfcorocher
Copy link

Hello @sarahdayan , I'm trying to fix the bug but I have doubt in allocate function. It should only accepts integer numbers in validation or float number can be accept too? For example, should allocate function accept these arguments?

Dinero({ amount: 100 }).allocate([48.5, 51.5 ])

@sarahdayan
Copy link
Collaborator

Hey @matheusfcorocher, and sorry for the late answer. Only integers should be accepted.

sarahdayan pushed a commit that referenced this issue Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers v1 This concerns v1
Projects
None yet
Development

No branches or pull requests

3 participants