Skip to content

Commit e3c5996

Browse files
Merge branch 'main' into NODE-5958-parseToStructure
2 parents eeae36c + 2f0effb commit e3c5996

File tree

13 files changed

+205
-27
lines changed

13 files changed

+205
-27
lines changed

.evergreen/config.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ functions:
5050
args:
5151
- .evergreen/run-tests.sh
5252

53+
run big endian tests:
54+
- command: subprocess.exec
55+
type: test
56+
params:
57+
working_dir: src
58+
add_expansions_to_env: true
59+
binary: bash
60+
args:
61+
- .evergreen/run-big-endian-test.sh
62+
5363
run checks:
5464
- command: subprocess.exec
5565
type: test
@@ -236,7 +246,6 @@ tasks:
236246
- command: perf.send
237247
params:
238248
file: src/test/bench/etc/resultsCollectedMeans.json
239-
240249
- name: run-spec-benchmarks-node-18
241250
commands:
242251
- func: fetch source
@@ -257,12 +266,25 @@ tasks:
257266
NODE_LTS_VERSION: 20
258267
- func: install dependencies
259268
- func: run eslint plugin tests
269+
- name: node-tests-big-endian
270+
commands:
271+
- func: fetch source
272+
vars:
273+
NODE_LTS_VERSION: 20
274+
- func: install dependencies
275+
vars:
276+
NPM_OPTIONS: "--ignore-scripts"
277+
- func: run big endian tests
260278

261279
buildvariants:
262280
- name: linux
263281
display_name: RHEL 8.0
264282
run_on: rhel80-small
265283
tasks: [".node", ".web", "check-eslint-plugin"]
284+
- name: linux-zseries
285+
display_name: RHEL 8.3 zSeries
286+
run_on: rhel83-zseries-small
287+
tasks: ["node-tests-big-endian"]
266288
- name: lint
267289
display_name: lint
268290
run_on: rhel80-small

.evergreen/run-big-endian-test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
4+
5+
npx mocha test/s390x/big_endian.test.ts

HISTORY.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [6.5.0](https://github.com/mongodb/js-bson/compare/v6.4.0...v6.5.0) (2024-03-12)
6+
7+
8+
### Features
9+
10+
* **NODE-5506:** add Binary subtype sensitive ([#657](https://github.com/mongodb/js-bson/issues/657)) ([748ca60](https://github.com/mongodb/js-bson/commit/748ca6073c44c778f6a3f872ce009566b6e8601f))
11+
* **NODE-5957:** add BSON indexing API ([#654](https://github.com/mongodb/js-bson/issues/654)) ([2ac17ec](https://github.com/mongodb/js-bson/commit/2ac17ec1e3c53b280efa298d137d96b2176bf046))
12+
13+
14+
### Bug Fixes
15+
16+
* **NODE-6016:** flip byte order depending on system endianness ([#659](https://github.com/mongodb/js-bson/issues/659)) ([6a7ef5d](https://github.com/mongodb/js-bson/commit/6a7ef5da26b2f852711be23eb6dc84801d0a3ecf))
17+
518
## [6.4.0](https://github.com/mongodb/js-bson/compare/v6.3.0...v6.4.0) (2024-02-29)
619

720

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"vendor"
1515
],
1616
"types": "bson.d.ts",
17-
"version": "6.4.0",
17+
"version": "6.5.0",
1818
"author": {
1919
"name": "The MongoDB NodeJS Team",
2020
"email": "[email protected]"

src/binary.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export class Binary extends BSONValue {
5656
static readonly SUBTYPE_ENCRYPTED = 6;
5757
/** Column BSON type */
5858
static readonly SUBTYPE_COLUMN = 7;
59+
/** Sensitive BSON type */
60+
static readonly SUBTYPE_SENSITIVE = 8;
5961
/** User BSON type */
6062
static readonly SUBTYPE_USER_DEFINED = 128;
6163

src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export const BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
109109
/** Column BSON type @internal */
110110
export const BSON_BINARY_SUBTYPE_COLUMN = 7;
111111

112+
/** Sensitive BSON type @internal */
113+
export const BSON_BINARY_SUBTYPE_SENSITIVE = 8;
114+
112115
/** Binary User Defined Type @internal */
113116
export const BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
114117

src/utils/number_utils.ts

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const FLOAT = new Float64Array(1);
22
const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
33

4+
FLOAT[0] = -1;
5+
// Little endian [0, 0, 0, 0, 0, 0, 240, 191]
6+
// Big endian [191, 240, 0, 0, 0, 0, 0, 0]
7+
const isBigEndian = FLOAT_BYTES[7] === 0;
8+
49
/**
510
* Number parsing and serializing utilities.
611
*
@@ -50,17 +55,29 @@ export const NumberUtils = {
5055
},
5156

5257
/** Reads a little-endian 64-bit float from source */
53-
getFloat64LE(source: Uint8Array, offset: number): number {
54-
FLOAT_BYTES[0] = source[offset];
55-
FLOAT_BYTES[1] = source[offset + 1];
56-
FLOAT_BYTES[2] = source[offset + 2];
57-
FLOAT_BYTES[3] = source[offset + 3];
58-
FLOAT_BYTES[4] = source[offset + 4];
59-
FLOAT_BYTES[5] = source[offset + 5];
60-
FLOAT_BYTES[6] = source[offset + 6];
61-
FLOAT_BYTES[7] = source[offset + 7];
62-
return FLOAT[0];
63-
},
58+
getFloat64LE: isBigEndian
59+
? (source: Uint8Array, offset: number) => {
60+
FLOAT_BYTES[7] = source[offset];
61+
FLOAT_BYTES[6] = source[offset + 1];
62+
FLOAT_BYTES[5] = source[offset + 2];
63+
FLOAT_BYTES[4] = source[offset + 3];
64+
FLOAT_BYTES[3] = source[offset + 4];
65+
FLOAT_BYTES[2] = source[offset + 5];
66+
FLOAT_BYTES[1] = source[offset + 6];
67+
FLOAT_BYTES[0] = source[offset + 7];
68+
return FLOAT[0];
69+
}
70+
: (source: Uint8Array, offset: number) => {
71+
FLOAT_BYTES[0] = source[offset];
72+
FLOAT_BYTES[1] = source[offset + 1];
73+
FLOAT_BYTES[2] = source[offset + 2];
74+
FLOAT_BYTES[3] = source[offset + 3];
75+
FLOAT_BYTES[4] = source[offset + 4];
76+
FLOAT_BYTES[5] = source[offset + 5];
77+
FLOAT_BYTES[6] = source[offset + 6];
78+
FLOAT_BYTES[7] = source[offset + 7];
79+
return FLOAT[0];
80+
},
6481

6582
/** Writes a big-endian 32-bit integer to destination, can be signed or unsigned */
6683
setInt32BE(destination: Uint8Array, offset: number, value: number): 4 {
@@ -120,16 +137,29 @@ export const NumberUtils = {
120137
},
121138

122139
/** Writes a little-endian 64-bit float to destination */
123-
setFloat64LE(destination: Uint8Array, offset: number, value: number): 8 {
124-
FLOAT[0] = value;
125-
destination[offset] = FLOAT_BYTES[0];
126-
destination[offset + 1] = FLOAT_BYTES[1];
127-
destination[offset + 2] = FLOAT_BYTES[2];
128-
destination[offset + 3] = FLOAT_BYTES[3];
129-
destination[offset + 4] = FLOAT_BYTES[4];
130-
destination[offset + 5] = FLOAT_BYTES[5];
131-
destination[offset + 6] = FLOAT_BYTES[6];
132-
destination[offset + 7] = FLOAT_BYTES[7];
133-
return 8;
134-
}
140+
setFloat64LE: isBigEndian
141+
? (destination: Uint8Array, offset: number, value: number) => {
142+
FLOAT[0] = value;
143+
destination[offset] = FLOAT_BYTES[7];
144+
destination[offset + 1] = FLOAT_BYTES[6];
145+
destination[offset + 2] = FLOAT_BYTES[5];
146+
destination[offset + 3] = FLOAT_BYTES[4];
147+
destination[offset + 4] = FLOAT_BYTES[3];
148+
destination[offset + 5] = FLOAT_BYTES[2];
149+
destination[offset + 6] = FLOAT_BYTES[1];
150+
destination[offset + 7] = FLOAT_BYTES[0];
151+
return 8;
152+
}
153+
: (destination: Uint8Array, offset: number, value: number) => {
154+
FLOAT[0] = value;
155+
destination[offset] = FLOAT_BYTES[0];
156+
destination[offset + 1] = FLOAT_BYTES[1];
157+
destination[offset + 2] = FLOAT_BYTES[2];
158+
destination[offset + 3] = FLOAT_BYTES[3];
159+
destination[offset + 4] = FLOAT_BYTES[4];
160+
destination[offset + 5] = FLOAT_BYTES[5];
161+
destination[offset + 6] = FLOAT_BYTES[6];
162+
destination[offset + 7] = FLOAT_BYTES[7];
163+
return 8;
164+
}
135165
};

test/node/constants.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ describe('BSON Constants', () => {
1919
| "\x04" UUID
2020
| "\x05" MD5
2121
| "\x06" Encrypted BSON value
22+
| "\x07" Column BSON value
23+
| "\x08" Sensitive BSON value
2224
| "\x80" User defined
2325
*/
2426
it('Default should be 0', () => {
@@ -55,6 +57,11 @@ describe('BSON Constants', () => {
5557
expect(constants.BSON_BINARY_SUBTYPE_COLUMN).to.equal(7);
5658
expect(Binary.SUBTYPE_COLUMN).to.equal(7);
5759
});
60+
61+
it('Sensitive should be 8', () => {
62+
expect(constants.BSON_BINARY_SUBTYPE_SENSITIVE).to.equal(8);
63+
expect(Binary.SUBTYPE_SENSITIVE).to.equal(8);
64+
});
5865
});
5966
context('BSON Type indicators', () => {
6067
/*

test/node/double.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import { BSON, Double } from '../register-bson';
33

44
import { BSON_DATA_NUMBER, BSON_DATA_INT } from '../../src/constants';
55
import { inspect } from 'node:util';
6+
import { bufferFromHexArray } from './tools/utils';
7+
8+
const FLOAT = new Float64Array(1);
9+
const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
10+
11+
FLOAT[0] = -1;
12+
// Little endian [0, 0, 0, 0, 0, 0, 240, 191]
13+
// Big endian [191, 240, 0, 0, 0, 0, 0, 0]
14+
const isBigEndian = FLOAT_BYTES[7] === 0;
615

716
describe('BSON Double Precision', function () {
817
context('class Double', function () {
@@ -297,4 +306,22 @@ describe('BSON Double Precision', function () {
297306
});
298307
});
299308
});
309+
310+
context(`handles ${isBigEndian ? 'big' : 'little'} endianness correctly`, () => {
311+
const bsonWithFloat = bufferFromHexArray([
312+
'01', // double
313+
'6100', // 'a'
314+
'00'.repeat(6) + 'f0bf' // 8 byte LE float equal to -1
315+
]);
316+
317+
it('deserialize should return -1', () => {
318+
const res = BSON.deserialize(bsonWithFloat);
319+
expect(res).to.have.property('a', -1);
320+
});
321+
322+
it('serialize should set bytes to -1 in little endian format', () => {
323+
const res = BSON.serialize({ a: new Double(-1) });
324+
expect(res).to.deep.equal(bsonWithFloat);
325+
});
326+
});
300327
});

0 commit comments

Comments
 (0)