Skip to content

Conversation

ionut998
Copy link

Summary

Include False in the list of rules for coercion of user input.
Casting the string false or FALSE to boolean results in a false value but casting False to boolean results in true

Before:

ActiveRecord::Type::Boolean.new.cast("False")
=> true

After

ActiveRecord::Type::Boolean.new.cast("False")
=> false

Include `False` in the list of rules for coercion of user input.
Casting the string `false` or `FALSE` to boolean results in a `false` value but casting `False` to boolean results in `true`

Before:
```
ActiveRecord::Type::Boolean.new.cast("False")
=> true
```

After
```
ActiveRecord::Type::Boolean.new.cast("False")
=> false
```
@rafaelfranca
Copy link
Member

Thank you for the pull request but this is a huge change of behavior and we don't need to do it. Make sure the case of your string is consistent before passing to this method.

@ionut998
Copy link
Author

I still think it would be useful to have this in the framework. I know that there is an easy way around it and I understand that not all the permutations of lower and uppercase should be taken care of but False (in this casing) is quite a common one.

@ionut998 ionut998 deleted the fix_boolean_casting_for_false branch November 17, 2020 20:17
@rodolfobandeira
Copy link

+1 in favour to accept this PR. The behaviour of the class is broken. I'd actually go with value.downcase which would fix all cases: ie: falSE

@rafaelfranca @ionut998

@rafaelfranca
Copy link
Member

#40606 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants