yii2-mongodb
yii2-mongodb copied to clipboard
ext-mongodb crashes if empty collection name
What steps will reproduce the problem?
<?php
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
use yii\mongodb\Connection;
$connection = new Connection(['dsn' => 'mongodb://localhost:27017/test']);
var_dump($connection->getCollection('')->findOne());
What's expected?
Throw an exception
What do you get instead?
PHP crashes
mongo-c-driver/work/mongo-c-driver-1.17.1/src/libmongoc/src/mongoc/mongoc-cursor.c:1118
_mongoc_cursor_collection(): precondition failed: *collection_len > 0
Possible fix: in yii2-mongodb/src/Database.php
public function getCollection($name, $refresh = false)
{
if (empty($name)) {
throw new InvalidParamException('A non-empty collection "$name" is required');
}
...
}
That's a bit werid behavior for a mongodb driver. A check for empty collection won't hurt anyway.