FIX: ensures default required validator handles 0 (#28686)

Prior to this fix `0` would be erroring as non-existing and would raise the required error.
This commit is contained in:
Joffrey JAFFEUX 2024-09-02 20:46:04 +02:00 committed by GitHub
parent c180d1db1e
commit b771d3173f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import { isBlank } from "@ember/utils";
import I18n from "discourse-i18n";
export default class Validator {
@ -114,7 +115,7 @@ export default class Validator {
}
break;
default:
if (!value) {
if (isBlank(value)) {
error = true;
}
}

View File

@ -267,5 +267,10 @@ module("Unit | Lib | FormKit | Validator", function (hooks) {
[I18n.t("form_kit.errors.required")],
"it returns an error when the value is undefined"
);
errors = await new Validator(0, {
required: {},
}).validate("xxx");
assert.deepEqual(errors, [], "it returns no error when the value is 0");
});
});