Skip to content

Commit

Permalink
Merge pull request #715 from DirectoryTree/BUG-714
Browse files Browse the repository at this point in the history
Bug 714 - Reverse boolean casts no longer accept LDAP string booleans
  • Loading branch information
stevebauman committed May 8, 2024
2 parents 999f6ad + 7b785db commit d7c698e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Models/Concerns/HasAttributes.php
Expand Up @@ -578,8 +578,12 @@ protected function asBoolean(mixed $value): bool
/**
* Cast the value from a primitive boolean to an LDAP boolean string.
*/
protected function fromBoolean(bool $value): string
protected function fromBoolean(mixed $value): string
{
if (is_string($value)) {
$value = $this->asBoolean($value);
}

return $value ? 'TRUE' : 'FALSE';
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Models/ModelAttributeCastTest.php
Expand Up @@ -28,6 +28,10 @@ public function test_boolean_attributes_are_casted()
$this->assertTrue($model->booleanAttribute);
$this->assertEquals($model->getRawAttribute('booleanAttribute'), ['TRUE']);

$model->booleanAttribute = 'false';
$this->assertFalse($model->booleanAttribute);
$this->assertEquals($model->getRawAttribute('booleanAttribute'), ['FALSE']);

// Casing differences

$model = (new ModelCastStub)->setRawAttributes(['boolAttribute' => ['true']]);
Expand Down

0 comments on commit d7c698e

Please sign in to comment.