Skip to content

Commit 0722e8f

Browse files
committed
Merge branch 'master' into 8.10
2 parents aeaa95c + 8cfc517 commit 0722e8f

File tree

16 files changed

+197
-97
lines changed

16 files changed

+197
-97
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
fetch-depth: 0
2828
- name: Setup node
29-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
29+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
3030
with:
3131
node-version: 22
3232

.github/workflows/documentation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3232

3333
- name: Setup node
34-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
34+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
3535
with:
3636
node-version: 22
3737

@@ -52,7 +52,7 @@ jobs:
5252
- run: git fetch --depth=1 --tags # download all tags for documentation
5353

5454
- name: Setup node
55-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
55+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
5656
with:
5757
node-version: 22
5858

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2626

2727
- name: Setup node
28-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
28+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2929
with:
3030
node-version: 22
3131

@@ -61,7 +61,7 @@ jobs:
6161
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6262

6363
- name: Setup node
64-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
64+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
6565
with:
6666
node-version: ${{ matrix.node }}
6767

@@ -96,7 +96,7 @@ jobs:
9696
steps:
9797
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
9898
- name: Setup node
99-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
99+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
100100
with:
101101
node-version: 22
102102
- name: Load MongoDB binary cache
@@ -124,7 +124,7 @@ jobs:
124124
steps:
125125
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
126126
- name: Setup node
127-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
127+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
128128
with:
129129
node-version: 22
130130
- run: npm install

.github/workflows/tidelift-alignment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1919
- name: Setup node
20-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
20+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2121
with:
2222
node-version: 22
2323
- name: Alignment

.github/workflows/tsd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2424

2525
- name: Setup node
26-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
26+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2727
with:
2828
node-version: 22
2929

@@ -41,7 +41,7 @@ jobs:
4141
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4242

4343
- name: Setup node
44-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
44+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
4545
with:
4646
node-version: 22
4747

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
8.9.6 / 2025-01-31
2+
==================
3+
* fix(document): allow setting values to undefined with set(obj) syntax with strict: false #15207 #15192
4+
* fix(schema): improve reason for UUID cast error, currently a TypeError #15215 #15202
5+
* fix(aggregate): improve error when calling near() with invalid coordinates #15206 #15188
6+
17
7.8.6 / 2025-01-20
28
===================
39
* chore: remove coverage output from bundle

lib/aggregate.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,23 @@ Aggregate.prototype.project = function(arg) {
397397
* @memberOf Aggregate
398398
* @instance
399399
* @param {Object} arg
400+
* @param {Object|Array<Number>} arg.near GeoJSON point or coordinates array
400401
* @return {Aggregate}
401402
* @api public
402403
*/
403404

404405
Aggregate.prototype.near = function(arg) {
406+
if (arg == null) {
407+
throw new MongooseError('Aggregate `near()` must be called with non-nullish argument');
408+
}
409+
if (arg.near == null) {
410+
throw new MongooseError('Aggregate `near()` argument must have a `near` property');
411+
}
412+
const coordinates = Array.isArray(arg.near) ? arg.near : arg.near.coordinates;
413+
if (typeof arg.near === 'object' && (!Array.isArray(coordinates) || coordinates.length < 2 || coordinates.find(c => typeof c !== 'number'))) {
414+
throw new MongooseError(`Aggregate \`near()\` argument has invalid coordinates, got "${coordinates}"`);
415+
}
416+
405417
const op = {};
406418
op.$geoNear = arg;
407419
return this.append(op);

lib/cast/uuid.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
const MongooseBuffer = require('../types/buffer');
4+
5+
const UUID_FORMAT = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i;
6+
const Binary = MongooseBuffer.Binary;
7+
8+
module.exports = function castUUID(value) {
9+
if (value == null) {
10+
return value;
11+
}
12+
13+
function newBuffer(initbuff) {
14+
const buff = new MongooseBuffer(initbuff);
15+
buff._subtype = 4;
16+
return buff;
17+
}
18+
19+
if (typeof value === 'string') {
20+
if (UUID_FORMAT.test(value)) {
21+
return stringToBinary(value);
22+
} else {
23+
throw new Error(`"${value}" is not a valid UUID string`);
24+
}
25+
}
26+
27+
if (Buffer.isBuffer(value)) {
28+
return newBuffer(value);
29+
}
30+
31+
if (value instanceof Binary) {
32+
return newBuffer(value.value(true));
33+
}
34+
35+
// Re: gh-647 and gh-3030, we're ok with casting using `toString()`
36+
// **unless** its the default Object.toString, because "[object Object]"
37+
// doesn't really qualify as useful data
38+
if (value.toString && value.toString !== Object.prototype.toString) {
39+
if (UUID_FORMAT.test(value.toString())) {
40+
return stringToBinary(value.toString());
41+
}
42+
}
43+
44+
throw new Error(`"${value}" cannot be casted to a UUID`);
45+
};
46+
47+
module.exports.UUID_FORMAT = UUID_FORMAT;
48+
49+
/**
50+
* Helper function to convert the input hex-string to a buffer
51+
* @param {String} hex The hex string to convert
52+
* @returns {Buffer} The hex as buffer
53+
* @api private
54+
*/
55+
56+
function hex2buffer(hex) {
57+
// use buffer built-in function to convert from hex-string to buffer
58+
const buff = hex != null && Buffer.from(hex, 'hex');
59+
return buff;
60+
}
61+
62+
/**
63+
* Convert a String to Binary
64+
* @param {String} uuidStr The value to process
65+
* @returns {MongooseBuffer} The binary to store
66+
* @api private
67+
*/
68+
69+
function stringToBinary(uuidStr) {
70+
// Protect against undefined & throwing err
71+
if (typeof uuidStr !== 'string') uuidStr = '';
72+
const hex = uuidStr.replace(/[{}-]/g, ''); // remove extra characters
73+
const bytes = hex2buffer(hex);
74+
const buff = new MongooseBuffer(bytes);
75+
buff._subtype = 4;
76+
77+
return buff;
78+
}

lib/document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
11471147
} else if (pathtype === 'nested' && valForKey == null) {
11481148
this.$set(pathName, valForKey, constructing, options);
11491149
}
1150-
} else if (valForKey !== void 0) {
1150+
} else {
11511151
this.$set(pathName, valForKey, constructing, options);
11521152
}
11531153
}

lib/helpers/document/applyDefaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ module.exports = function applyDefaults(doc, fields, exclude, hasIncludedChildre
1919
const type = doc.$__schema.paths[p];
2020
const path = type.splitPath();
2121
const len = path.length;
22+
if (path[len - 1] === '$*') {
23+
continue;
24+
}
2225
let included = false;
2326
let doc_ = doc._doc;
2427
for (let j = 0; j < len; ++j) {

0 commit comments

Comments
 (0)