Skip to content

Commit

Permalink
Fix yiisoft#20122: Fixed parsing of boolean keywords (e.g. used in SQ…
Browse files Browse the repository at this point in the history
…Lite) in `\yii\db\ColumnSchema::typecast()`
  • Loading branch information
rhertogh authored Mar 3, 2024
1 parent 78cc719 commit 283499c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Yii Framework 2 Change Log
- Bug #13920: Fixed erroneous validation for specific cases (tim-fischer-maschinensucher)
- Bug #19927: Fixed `console\controllers\MessageController` when saving translations to database: fixed FK error when adding new string and language at the same time, checking/regenerating all missing messages and dropping messages for unused languages (atrandafir)
- Bug #20002: Fixed superfluous query on HEAD request in serializer (xicond)
- Bug #20122: Fixed parsing of boolean keywords (e.g. used in SQLite) in `\yii\db\ColumnSchema::typecast()` (rhertogh)
- Enh #12743: Added new methods `BaseActiveRecord::loadRelations()` and `BaseActiveRecord::loadRelationsFor()` to eager load related models for existing primary model instances (PowerGamer1)
- Enh #20030: Improve performance of handling `ErrorHandler::$memoryReserveSize` (antonshevelev, rob006)
- Enh #20042: Add empty array check to `ActiveQueryTrait::findWith()` (renkas)
Expand Down
2 changes: 1 addition & 1 deletion framework/db/ColumnSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected function typecast($value)
case 'boolean':
// treating a 0 bit value as false too
// https://github.com/yiisoft/yii2/issues/9006
return (bool) $value && $value !== "\0";
return (bool) $value && $value !== "\0" && strtolower($value) !== 'false';
case 'double':
return (float) $value;
}
Expand Down
33 changes: 33 additions & 0 deletions tests/framework/db/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,39 @@ public function testColumnSchemaDbTypecastWithEmptyCharType()
$this->assertSame('', $columnSchema->dbTypecast(''));
}

/**
* @dataProvider columnSchemaDbTypecastBooleanPhpTypeProvider
* @param mixed $value
* @param bool $expected
*/
public function testColumnSchemaDbTypecastBooleanPhpType($value, $expected)
{
$columnSchema = new ColumnSchema(['phpType' => Schema::TYPE_BOOLEAN]);
$this->assertSame($expected, $columnSchema->dbTypecast($value));
}

public function columnSchemaDbTypecastBooleanPhpTypeProvider()
{
return [
[1, true],
[0, false],
['1', true],
['0', false],

// https://github.com/yiisoft/yii2/issues/9006
["\1", true],
["\0", false],

// https://github.com/yiisoft/yii2/pull/20122
['TRUE', true],
['FALSE', false],
['true', true],
['false', false],
['True', true],
['False', false],
];
}

public function testFindUniqueIndexes()
{
if ($this->driverName === 'sqlsrv') {
Expand Down

0 comments on commit 283499c

Please sign in to comment.