fix(Decimal128): throw error when passing a string to Decimal128 constructor

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      https://github.com/mongodb/js-bson/pull/322

      You can get some nasty surprises when you pass a string to the Decimal128 constructor:

      const bson = require('bson');
      
      const v = new bson.Decimal128('14.92');
      
      // {"$numberDecimal":"8.740930561E-6167"}
      console.log(JSON.stringify(v));
      

      Would be handy to at least throw an error. Although is there some reason why we can't just do fromString() if the user passes a string instead of a buffer to the Decimal128 constructor?

              Assignee:
              Unassigned
              Reporter:
              Alexander Golin (Inactive)
              None
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated: