Skip to content

Commit 062016e

Browse files
committed
fix(projection): avoid setting projection to unknown exclusive/inclusive if elemMatch on a Date, ObjectId, etc.
Fix Automattic#14893
1 parent 3cfd3f6 commit 062016e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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
}
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+
});

0 commit comments

Comments
 (0)