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

Fix reading blob data as resource #33129

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/public/AppFramework/Db/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ protected function setter($name, $args) {
$type = $this->_fieldTypes[$name];
if ($type === 'blob') {
// (B)LOB is treated as string when we read from the DB
if (is_resource($args[0])) {
$args[0] = stream_get_contents($args[0]);
}
$type = 'string';
}

Expand Down
17 changes: 17 additions & 0 deletions tests/lib/AppFramework/Db/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* @method bool getAnotherBool()
* @method bool isAnotherBool()
* @method void setAnotherBool(bool $anotherBool)
* @method string getLongText()
* @method void setLongText(string $longText)
*/
class TestEntity extends Entity {
protected $name;
Expand All @@ -51,11 +53,13 @@ class TestEntity extends Entity {
protected $preName;
protected $trueOrFalse;
protected $anotherBool;
protected $longText;

public function __construct($name = null) {
$this->addType('testId', 'integer');
$this->addType('trueOrFalse', 'bool');
$this->addType('anotherBool', 'boolean');
$this->addType('longText', 'blob');
$this->name = $name;
}
}
Expand Down Expand Up @@ -210,6 +214,18 @@ public function testSetterDoesNotCastOnNull() {
$this->assertSame(null, $entity->getId());
}

public function testSetterConvertsResourcesToStringProperly() {
$string = 'Definitely a string';
$stream = fopen('php://memory', 'r+');
fwrite($stream, $string);
rewind($stream);

$entity = new TestEntity();
$entity->setLongText($stream);
fclose($stream);
$this->assertSame($string, $entity->getLongText());
}


public function testGetFieldTypes() {
$entity = new TestEntity();
Expand All @@ -218,6 +234,7 @@ public function testGetFieldTypes() {
'testId' => 'integer',
'trueOrFalse' => 'bool',
'anotherBool' => 'boolean',
'longText' => 'blob',
], $entity->getFieldTypes());
}

Expand Down