Commit 56395109 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-69: Do not allow empty index name for dropIndex()

parent 33f6ca4d
...@@ -401,13 +401,16 @@ class Collection ...@@ -401,13 +401,16 @@ class Collection
* @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndex/ * @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndex/
* @param string $indexName * @param string $indexName
* @return Cursor * @return Cursor
* @throws InvalidArgumentException if "*" is specified, since dropIndexes() * @throws InvalidArgumentException if $indexName is an empty string or "*"
* should be used to drop multiple indexes
*/ */
public function dropIndex($indexName) public function dropIndex($indexName)
{ {
$indexName = (string) $indexName; $indexName = (string) $indexName;
if ($indexName === '') {
throw new InvalidArgumentException('Index name cannot be empty');
}
if ($indexName === '*') { if ($indexName === '*') {
throw new InvalidArgumentException('dropIndexes() must be used to drop multiple indexes'); throw new InvalidArgumentException('dropIndexes() must be used to drop multiple indexes');
} }
......
...@@ -150,6 +150,16 @@ class CollectionFunctionalTest extends FunctionalTestCase ...@@ -150,6 +150,16 @@ class CollectionFunctionalTest extends FunctionalTestCase
} }
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testDropIndexShouldNotAllowEmptyIndexName()
{
$this->assertSame('x_1', $this->collection->createIndex(array('x' => 1)));
$this->assertIndexExists('x_1');
$this->collection->dropIndex('');
}
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException * @expectedException MongoDB\Exception\InvalidArgumentException
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment