DBRef stringify loses type information in mongodb-query-parser

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      OS:
      node.js / npm versions:
      Additional info:
    • Not Needed
    • None
    • Developer Tools

      The code: https://github.com/mongodb-js/devtools-shared/blob/f1cd6a2276c04ccf82c8f92065ab10f9854e7cce/packages/query-parser/src/stringify.ts#L82 

      There are 2 bugs to fix here:

      1. v.oid.toString() is always wrapped in single quotes, so any non-string oid round-trips into a string:

      • DBRef('col', ObjectId('5e5ea7558d35931a05eafec0')) becomes DBRef('col', '5e5ea7558d35931a05eafec0') an ObjectId becomes a string, which is the common case and will not match the same documents.
      • DBRef('col', 1) → DBRef('col', '1')

      2. No escaping in collection/db. DBRef("it's", 1)DBRef('it's', '1'), which is syntactically broken and unparseable. JSON.stringify(v.collection) would handle it (as Code and RegExp already do in the same file).

            Assignee:
            Unassigned
            Reporter:
            Rhys Howell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: