Skip to content

Commit c6bd31d

Browse files
committed
Merge branch '7.x'
2 parents 34ed360 + 3ede837 commit c6bd31d

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
7.8.2 / 2024-09-25
2+
==================
3+
* fix(projection): avoid setting projection to unknown exclusive/inclusive if elemMatch on a Date, ObjectId, etc. #14894 #14893
4+
15
8.6.3 / 2024-09-17
26
==================
37
* fix: make getters convert uuid to string when calling toObject() and toJSON() #14890 #14869

lib/helpers/projection/isExclusive.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const isDefiningProjection = require('./isDefiningProjection');
4+
const isPOJO = require('../isPOJO');
45

56
/*!
67
* ignore
@@ -22,10 +23,12 @@ module.exports = function isExclusive(projection) {
2223
// Explicitly avoid `$meta` and `$slice`
2324
const key = keys[ki];
2425
if (key !== '_id' && isDefiningProjection(projection[key])) {
25-
exclude = (projection[key] != null && typeof projection[key] === 'object') ?
26-
isExclusive(projection[key]) :
26+
exclude = isPOJO(projection[key]) ?
27+
(isExclusive(projection[key]) ?? exclude) :
2728
!projection[key];
28-
break;
29+
if (exclude != null) {
30+
break;
31+
}
2932
}
3033
}
3134
}

lib/helpers/projection/isInclusive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const isDefiningProjection = require('./isDefiningProjection');
4+
const isPOJO = require('../isPOJO');
45

56
/*!
67
* ignore
@@ -26,7 +27,7 @@ module.exports = function isInclusive(projection) {
2627
// If field is truthy (1, true, etc.) and not an object, then this
2728
// projection must be inclusive. If object, assume its $meta, $slice, etc.
2829
if (isDefiningProjection(projection[prop]) && !!projection[prop]) {
29-
if (projection[prop] != null && typeof projection[prop] === 'object') {
30+
if (isPOJO(projection[prop])) {
3031
return isInclusive(projection[prop]);
3132
} else {
3233
return !!projection[prop];
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
5+
require('../common'); // required for side-effect setup (so that the default driver is set-up)
6+
const isExclusive = require('../../lib/helpers/projection/isExclusive');
7+
8+
describe('isExclusive', function() {
9+
it('handles $elemMatch (gh-14893)', function() {
10+
assert.strictEqual(isExclusive({ field: { $elemMatch: { test: new Date('2024-06-01') } }, otherProp: 1 }), false);
11+
});
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
5+
require('../common'); // required for side-effect setup (so that the default driver is set-up)
6+
const isInclusive = require('../../lib/helpers/projection/isInclusive');
7+
8+
describe('isInclusive', function() {
9+
it('handles $elemMatch (gh-14893)', function() {
10+
assert.strictEqual(isInclusive({ field: { $elemMatch: { test: new Date('2024-06-01') } }, otherProp: 1 }), true);
11+
});
12+
});

0 commit comments

Comments
 (0)