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

Bad values in boolean columns being converted to boolean values, rather than being caught by validators #71

Open
seanccsmith opened this issue Jun 8, 2020 · 1 comment
Assignees

Comments

@seanccsmith
Copy link
Contributor

As discovered when dealing with issue #61 , Boolean typed columns are being converted before they reach the validators. It looks like this was a workaround from before the validators were implemented, and should probably be deprecated now in favor of allowing the validators to catch any bad values and requiring the user to explicitly change them to an allowed value.

@seanccsmith
Copy link
Contributor Author

seanccsmith commented Jun 8, 2020

This is the code snippet Ken found that's controlling this, I'm not sure exactly where it's located in DURC:

public static function formatForStorage( $field_name, $field_type, $value, $model = null)
{

    $formattedValue = $value;
    if ( self::mapColumnDataTypeToInputType( $field_type, $field_name ) == 'boolean' ) {
		//support obvious notions of truth
        if ( $value === 'on' || $value === 'true' || $value === true || $value > 0 ) {
	//this allows us to support the use of 'on'/'true' etc  for trueness
            $formattedValue = 1;
        } else {
	//if it is a boolean and it is not obviously true.. then it is false..
            $formattedValue = 0;
        }

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

No branches or pull requests

2 participants