Skip to content

Commit c6af1a8

Browse files
pr comments
1 parent a9c1b3f commit c6af1a8

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

src/binary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export class Binary {
278278
if (!data) {
279279
throw new BSONTypeError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`);
280280
}
281-
return type === 4 ? new UUID(data) : new Binary(data, type);
281+
return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
282282
}
283283

284284
/** @internal */

src/parser/deserializer.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,10 @@ function deserializeObject(
445445

446446
if (promoteBuffers && promoteValues) {
447447
value = _buffer;
448+
} else if (subType === constants.BSON_BINARY_SUBTYPE_UUID_NEW) {
449+
value = new Binary(buffer.slice(index, index + binarySize), subType).toUUID();
448450
} else {
449-
value = new Binary(_buffer, subType);
450451
value = new Binary(buffer.slice(index, index + binarySize), subType);
451-
if (subType === constants.BSON_BINARY_SUBTYPE_UUID_NEW) {
452-
value = value.toUUID();
453-
}
454452
}
455453
}
456454

test/node/extended_json_tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ Converting circular structure to EJSON:
779779
const stringifiedUUID = EJSON.stringify({ uuid: exampleUUID });
780780
const parsedUUID = EJSON.parse(stringifiedUUID);
781781
const expectedResult = {
782-
uuid: new UUID('878dac1201cc4830b271cbc8518e63ad')
782+
uuid: new UUID('878dac12-01cc-4830-b271-cbc8518e63ad')
783783
};
784784
expect(parsedUUID).to.deep.equal(expectedResult);
785785
});

test/node/uuid_tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe('UUID', () => {
198198
const serializedUUID = BSON.serialize({ uuid: exampleUUID });
199199
const deserializedUUID = BSON.deserialize(serializedUUID);
200200
const expectedResult = {
201-
uuid: new UUID('878dac1201cc4830b271cbc8518e63ad')
201+
uuid: new UUID('878dac12-01cc-4830-b271-cbc8518e63ad')
202202
};
203203
expect(deserializedUUID).to.deep.equal(expectedResult);
204204
});

0 commit comments

Comments
 (0)