Patch 14734 boolean sync validators#15208
Conversation
Change synchronous validators to convert the return to boolean value. Prevent unexpected behavior when returning `undefined`. Closes angular#14734 BREAKING CHANGE: Previously, only a literal `false` return would resolve as the synchronous validator failing. Now, all traditionally false JavaScript values are treated as failing the validator, as one would naturally expect. To migrate, make sure your synchronous validators are returning either a literal `true` or a literal `false` value. For most code, we expect this to already be the case. Only a very small subset of projects will affected. Namely, anyone using `undefined` or any falsy value as a return will now see their validation failing, whereas previously falsy values other than `undefined` would have been seen as passing and `undefined` would have been seen as pending.
gkalpak
left a comment
There was a problem hiding this comment.
Apart from a couple of nitpicks, LGTM.
I would add a little more details to the commit message (regarding what was happening before) - can be done while merging.
| }); | ||
|
|
||
| it('should treat all responses as boolean for synchronous validators', function() { | ||
| var curry = function(v) { |
There was a problem hiding this comment.
You don't need a new function for this. You can use the internal helper: valueFn()
There was a problem hiding this comment.
Interesting, I'll make the switch. I was actually hoping to talk about the curry() anyways, because it's now used three times in this file (hence why I used it in the first place). I'll submit a separate PR to fix the others.
There was a problem hiding this comment.
Good catch! Feel free to change all other instances too.
| }; | ||
| }; | ||
|
|
||
| var tester = function(v, e) { |
There was a problem hiding this comment.
Nit: I would prefer a more descriptive name, such as expectValid().
Change synchronous validators to convert the return to boolean value. Prevent unexpected behavior when returning `undefined`. Closes angular#14734 BREAKING CHANGE: Previously, only a literal `false` return would resolve as the synchronous validator failing. Now, all traditionally false JavaScript values are treated as failing the validator, as one would naturally expect. Specifically, the values `0` (the number zero), `null`, `NaN` and `''` (the empty string) used to considered valid (passing) and they are now considered invalid (failing). The value `undefined` was treated similarly to a pending asynchronous validator, causing the validation to be pending. `undefined` is also now considered invalid. To migrate, make sure your synchronous validators are returning either a literal `true` or a literal `false` value. For most code, we expect this to already be the case. Only a very small subset of projects will be affected. Namely, anyone using `undefined` or any falsy value as a return will now see their validation failing, whereas previously falsy values other than `undefined` would have been seen as passing and `undefined` would have been seen as pending.
Change synchronous validators to convert the return to boolean value. Prevent unexpected behavior when returning `undefined`. Closes angular#14734 BREAKING CHANGE: Previously, only a literal `false` return would resolve as the synchronous validator failing. Now, all traditionally false JavaScript values are treated as failing the validator, as one would naturally expect. Specifically, the values `0` (the number zero), `null`, `NaN` and `''` (the empty string) used to considered valid (passing) and they are now considered invalid (failing). The value `undefined` was treated similarly to a pending asynchronous validator, causing the validation to be pending. `undefined` is also now considered invalid. To migrate, make sure your synchronous validators are returning either a literal `true` or a literal `false` value. For most code, we expect this to already be the case. Only a very small subset of projects will be affected. Namely, anyone using `undefined` or any falsy value as a return will now see their validation failing, whereas previously falsy values other than `undefined` would have been seen as passing and `undefined` would have been seen as pending.
Change synchronous validators to convert the return to boolean value. Prevent unexpected behavior when returning `undefined`. Closes angular#14734 BREAKING CHANGE: Previously, only a literal `false` return would resolve as the synchronous validator failing. Now, all traditionally false JavaScript values are treated as failing the validator, as one would naturally expect. Specifically, the values `0` (the number zero), `null`, `NaN` and `''` (the empty string) used to considered valid (passing) and they are now considered invalid (failing). The value `undefined` was treated similarly to a pending asynchronous validator, causing the validation to be pending. `undefined` is also now considered invalid. To migrate, make sure your synchronous validators are returning either a literal `true` or a literal `false` value. For most code, we expect this to already be the case. Only a very small subset of projects will be affected. Namely, anyone using `undefined` or any falsy value as a return will now see their validation failing, whereas previously falsy values other than `undefined` would have been seen as passing and `undefined` would have been seen as pending.
|
Hopefully those changes to the commit message are in the direction you wanted. |
|
Landed thanks. |
Change synchronous validators to convert the return to boolean value. Prevent unexpected behavior when returning `undefined`. Closes angular#14734 Closes angular#15208 BREAKING CHANGE: Previously, only a literal `false` return would resolve as the synchronous validator failing. Now, all traditionally false JavaScript values are treated as failing the validator, as one would naturally expect. Specifically, the values `0` (the number zero), `null`, `NaN` and `''` (the empty string) used to considered valid (passing) and they are now considered invalid (failing). The value `undefined` was treated similarly to a pending asynchronous validator, causing the validation to be pending. `undefined` is also now considered invalid. To migrate, make sure your synchronous validators are returning either a literal `true` or a literal `false` value. For most code, we expect this to already be the case. Only a very small subset of projects will be affected. Namely, anyone using `undefined` or any falsy value as a return will now see their validation failing, whereas previously falsy values other than `undefined` would have been seen as passing and `undefined` would have been seen as pending.
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Fix/clarification of how synchronous validators work.
What is the current behavior? (You can also link to an open issue here)
#14734 All values except
falseliteral andundefinedare treated as a pass.undefinedis treated as pending, which makes no sense for synchronous operation.What is the new behavior (if this is a feature change)?
All falsy value returns to a synchronous validator are treated as fails, including
undefined.Does this PR introduce a breaking change?
Yes, see commit message.
Please check if the PR fulfills these requirements
Other information:
I believe a change to docs in unnecessary. We still expect
trueandfalseto be the primary returns and don't want to encourage otherwise. This is mostly clarifying a niche, undocumented, edge-case to behave more intuitively.