Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5068

ElemMatch matcher operates on pre-stringified keys in condition verification path against impossible values

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.2
    • Affects Version/s: 7.2.1
    • Component/s: Query
    • Labels:
      None
    • Fully Compatible

      In the ElemMatch matcher, if the value in the target document is not an array, the matching will always return false but the matcher verifies that the condition contains legal operators, to match the server behavior. The condition verifier permits inner operators (condition keys) to be strings or symbols, and is meant to stringify the keys before operating on them.

      When the sub-operator under $elemMatch is given as a symbol, the stringification is done as part of a single check and not for all checks. Thus, the verification fails because an operator is looked up using symbol argument when the lookup table only contains string keys.

      To reproduce, perform $elemMatch with sub-operator given as a symbol against an empty document.

      -------

      Original report:

      Mongoid::Matcher::ElemMatch.matches?() didn't consistently convert input keys within its condition to Strings. This PR doesn't include a new unit test verifying this behavior because ElemMatch is clearly out of sync with the k = k.to_s pattern used in other lib/Mongoid/matcher/*.rb files. Existing examples of correctly using k = k.to_s in other of these Matcher sub-modules are:

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            dalton.black@braze.com Dalton Black
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: