Skip to content

Commit e70bba7

Browse files
rhertoghskepticspriggan
authored andcommitted
Fix yiisoft#20122: Fixed parsing of boolean keywords (e.g. used in SQLite) in \yii\db\ColumnSchema::typecast()
1 parent 081d8f4 commit e70bba7

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Yii Framework 2 Change Log
1414
- Bug #13920: Fixed erroneous validation for specific cases (tim-fischer-maschinensucher)
1515
- 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)
1616
- Bug #20002: Fixed superfluous query on HEAD request in serializer (xicond)
17+
- Bug #20122: Fixed parsing of boolean keywords (e.g. used in SQLite) in `\yii\db\ColumnSchema::typecast()` (rhertogh)
1718
- Enh #12743: Added new methods `BaseActiveRecord::loadRelations()` and `BaseActiveRecord::loadRelationsFor()` to eager load related models for existing primary model instances (PowerGamer1)
1819
- Enh #20030: Improve performance of handling `ErrorHandler::$memoryReserveSize` (antonshevelev, rob006)
1920
- Enh #20042: Add empty array check to `ActiveQueryTrait::findWith()` (renkas)

framework/db/ColumnSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected function typecast($value)
174174
case 'boolean':
175175
// treating a 0 bit value as false too
176176
// https://github.com/yiisoft/yii2/issues/9006
177-
return (bool) $value && $value !== "\0";
177+
return (bool) $value && $value !== "\0" && strtolower($value) !== 'false';
178178
case 'double':
179179
return (float) $value;
180180
}

tests/framework/db/SchemaTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,39 @@ public function testColumnSchemaDbTypecastWithEmptyCharType()
545545
$this->assertSame('', $columnSchema->dbTypecast(''));
546546
}
547547

548+
/**
549+
* @dataProvider columnSchemaDbTypecastBooleanPhpTypeProvider
550+
* @param mixed $value
551+
* @param bool $expected
552+
*/
553+
public function testColumnSchemaDbTypecastBooleanPhpType($value, $expected)
554+
{
555+
$columnSchema = new ColumnSchema(['phpType' => Schema::TYPE_BOOLEAN]);
556+
$this->assertSame($expected, $columnSchema->dbTypecast($value));
557+
}
558+
559+
public function columnSchemaDbTypecastBooleanPhpTypeProvider()
560+
{
561+
return [
562+
[1, true],
563+
[0, false],
564+
['1', true],
565+
['0', false],
566+
567+
// https://github.com/yiisoft/yii2/issues/9006
568+
["\1", true],
569+
["\0", false],
570+
571+
// https://github.com/yiisoft/yii2/pull/20122
572+
['TRUE', true],
573+
['FALSE', false],
574+
['true', true],
575+
['false', false],
576+
['True', true],
577+
['False', false],
578+
];
579+
}
580+
548581
public function testFindUniqueIndexes()
549582
{
550583
if ($this->driverName === 'sqlsrv') {

0 commit comments

Comments
 (0)