Ver Fonte

Merge pull request #66 from alcaeus/harden-mongoid-type-check

Harden type checks in MongoId::isValid
Andreas há 10 anos atrás
pai
commit
849de05fe5

+ 2 - 0
lib/Mongo/MongoId.php

@@ -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);

+ 1 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoIdTest.php

@@ -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()],
         ];
     }
 }