-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
isMultipleOf() false negatives? #172
Comments
Isn't that how it should work? 🤔
|
Yeah, I think it's correct, but then all other validators are wrong... I mean, I don't know if the others are coercing somehow such long values. That's the question. I'm want to use But then it happens: such values are generated and only the validation made by this module didn't passed. TBH probably it's wrong behavior from my side, just I'm investigating. 💣 |
Hmm 🤔 A possible solution could be to change That could potentially let something thru that someone isn't expecting though 🤔 Appreciate the investigations! 🙌 |
I made a change: var isMultipleOf = function(name, multipleOf) {
var res;
var factor = ((multipleOf | 0) !== multipleOf) ? Math.pow(10, multipleOf.toString().split('.').pop().length) : 1
if (factor > 1) {
var factorName = ((name | 0) !== name) ? Math.pow(10, name.toString().split('.').pop().length) : 1
- if (factorName > factor) res = true
+ if (factorName > factor) res = (factorName / factor) % factor
else res = Math.round(factor * name) % (factor * multipleOf)
}
else res = name % multipleOf;
return !res;
} The code I changed was related to With that change my tests are passing now, without issues. Also tests from
I wonder if that's fine and could be a PR? |
So I found a bug? 🤔 |
I'm validating this value:
...against the schema:
...but is failing with 'has a remainder' which I think is bit wrong?
Also I tested the same sample/schema with: tv4, z-schema and jayschema and it there's no problem.
I noticed that
0.47
passesisMultipleOf
as expected but then the other validators fails...The text was updated successfully, but these errors were encountered: