Skip to content

fix(shell-bson-parser): do not treat own _bsontype field as a BSON value in toJSString COMPASS-11375 - #970

Merged
dudaschar merged 2 commits into
mainfrom
COMPASS-11375
Nov 13, 2026
Merged

dudaschar merged 2 commits into
mainfrom
COMPASS-11375

Conversation

@dudaschar

Copy link
Copy Markdown
Collaborator

Description

toJSString decides whether a value is a BSON type by reading value._bsontype. That also matches a plain object that has its own _bsontype field, such as a document read from the server, so it was run through the BSON serializer and its field values were interpolated into the generated source as-is.

BSON class instances define _bsontype on the prototype. This change treats an object with an own _bsontype property as a plain object, so it is serialized like any other object. Real BSON values are serialized as before.

Notes

  • A regression test will follow in a separate PR.

Open Questions

Checklist

@dudaschar dudaschar self-assigned this Nov 13, 2026
@dudaschar
dudaschar requested review from a team as code owners November 13, 2026 10:18
@dudaschar
dudaschar requested review from alenakhineika and a balanced review from Copilot November 13, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The guard breaks serialization of supported BSON 4 ObjectIds, and regression coverage is missing for plain documents with their own _bsontype properties.

2 open issues
What changed in this PR

This PR updates shell-bson-parser to serialize documents with their own _bsontype field as ordinary objects, preventing their fields from being interpolated as BSON constructor arguments.

Changes:

  • Adds an own-property check before selecting BSON serialization.
  • Keeps prototype-based BSON detection; regression tests are deferred to a follow-up PR.
File Description
packages/​shell-bson-parser/​src/​stringify.ts Excludes objects with an own _bsontype property from BSON-specific serialization.

Review effort: Balanced

const _bsontype = t === 'Object' && value._bsontype;
const _bsontype =
t === 'Object' &&
!Object.prototype.hasOwnProperty.call(value, '_bsontype') &&

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are going to be added in a follow up PR

@dudaschar
dudaschar merged commit c4b820c into main Nov 13, 2026
19 checks passed
@dudaschar
dudaschar deleted the COMPASS-11375 branch November 13, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants