Skip to content
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
7 changes: 6 additions & 1 deletion src/Database/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ArrayObject;
use Utopia\Database\Exception as DatabaseException;
use Utopia\Database\Exception\Structure as StructureException;

/**
* @extends ArrayObject<string, mixed>
Expand All @@ -26,8 +27,12 @@ class Document extends ArrayObject
*/
public function __construct(array $input = [])
{
if (isset($input['$id']) && !\is_string($input['$id'])) {
throw new StructureException('$id must be of type string');
}

if (isset($input['$permissions']) && !is_array($input['$permissions'])) {
throw new DatabaseException('$permissions must be of type array');
throw new StructureException('$permissions must be of type array');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this so we do not get 500

}

foreach ($input as $key => &$value) {
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -3122,6 +3122,14 @@ public function testFind(): array
$this->assertEquals(true, static::getDatabase()->createAttribute('movies', 'with-dash', Database::VAR_STRING, 128, true));
$this->assertEquals(true, static::getDatabase()->createAttribute('movies', 'nullable', Database::VAR_STRING, 128, false));

try {
static::getDatabase()->createDocument('movies', new Document(['$id' => ['id_as_array']]));
$this->fail('Failed to throw exception');
} catch (Throwable $e) {
$this->assertEquals('$id must be of type string', $e->getMessage());
$this->assertInstanceOf(StructureException::class, $e);
}

$document = static::getDatabase()->createDocument('movies', new Document([
'$id' => ID::custom('frozen'),
'$permissions' => [
Expand Down
Loading