-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Use Case
As a js-bson user
I want UTF-8 validation of long string values during deserialization to be faster
So that default deserialization (validation on) costs less for documents with long strings
User Experience
No API change. For strings of 64 bytes or more, nodeJsByteUtils.toUTF8 with fatal: true validates the bytes with Node's native isUtf8 (from the buffer module) before decoding. Invalid input still goes through parseUtf8(..., true), so the error is unchanged. Shorter strings keep the current path. If isUtf8 is unavailable, the current path runs.
Dependencies
N/A
Risks/Unknowns
- Relies on an optional runtime API (isUtf8, reached via process.getBuiltinModule('buffer')), feature detected with fallback.
- Cross-driver alignment: N/A
Acceptance Criteria
Implementation Requirements
Change limited to src/utils/node_byte_utils.ts; web byte utils unchanged. Error message and cause for invalid UTF-8 unchanged.
Testing Requirements
New toUTF8 cases in test/node/byte_utils.test.ts (invalid sequences at the end of a long string; valid long string containing a literal U+FFFD).
Documentation Requirements
N/A
Follow Up Requirements
N/A