Uploaded image for project: 'PHP Legacy Driver'
  1. PHP Legacy Driver
  2. PHP-554

MongoId should not get constructed when passing in an invalid ID.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.3.7
    • Fix Version/s: 1.4.0beta1, 1.4.0
    • Component/s: pecl-mongo
    • Labels:
    • Environment:
      All
    • # Replies:
      5
    • Last comment by Customer:
      false

      Description

      You should not be able to construct a new instance of \MongoId with an invalid identifier. Currently, you are able to and it leads to inconsistencies as well as too many invalid queries.

      new \MongoId('i am not a valid id!') -> '509403bd3689a3f942000000' (a valid mongo id)

      Currently, before running all queries, we validate MongoId's, but I feel that this is a hack:

      if ($id !== (new \MongoId($id)->__toString()) throw new InvalidMongoIdException();

      Now we can track when users are passing in invalid ids and stop from unnecessary DB look-ups.

      I propose that a null argument is what creates a new MongoId, and when given an argument, it wraps the given ID in a MongoId object, and when invalid, an exception is thrown.

      Cheers!

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since reply:
                  4 years, 38 weeks, 2 days ago
                  Date of 1st Reply: