Harden type checks in MongoId::isValid
@@ -48,6 +48,8 @@ class MongoId implements Serializable, TypeInterface
{
if ($value instanceof ObjectID || $value instanceof MongoId) {
return true;
+ } elseif (! is_string($value)) {
+ return false;
}
return (bool) preg_match('#^[a-f0-9]{24}$#i', $value);
@@ -77,6 +77,7 @@ class MongoIdTest extends TestCase
'MongoId' => [true, new \MongoId($original)],
'ObjectID' => [true, new ObjectID($original)],
'invalidString' => [false, 'abc'],
+ 'object' => [false, new \stdClass()],
];