Skip to content

Commit

Permalink
Merge branch '7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Sep 25, 2024
2 parents 34ed360 + 3ede837 commit c6bd31d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
7.8.2 / 2024-09-25
==================
* fix(projection): avoid setting projection to unknown exclusive/inclusive if elemMatch on a Date, ObjectId, etc. #14894 #14893

8.6.3 / 2024-09-17
==================
* fix: make getters convert uuid to string when calling toObject() and toJSON() #14890 #14869
Expand Down
9 changes: 6 additions & 3 deletions lib/helpers/projection/isExclusive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const isDefiningProjection = require('./isDefiningProjection');
const isPOJO = require('../isPOJO');

/*!
* ignore
Expand All @@ -22,10 +23,12 @@ module.exports = function isExclusive(projection) {
// Explicitly avoid `$meta` and `$slice`
const key = keys[ki];
if (key !== '_id' && isDefiningProjection(projection[key])) {
exclude = (projection[key] != null && typeof projection[key] === 'object') ?
isExclusive(projection[key]) :
exclude = isPOJO(projection[key]) ?
(isExclusive(projection[key]) ?? exclude) :
!projection[key];
break;
if (exclude != null) {
break;
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/projection/isInclusive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const isDefiningProjection = require('./isDefiningProjection');
const isPOJO = require('../isPOJO');

/*!
* ignore
Expand All @@ -26,7 +27,7 @@ module.exports = function isInclusive(projection) {
// If field is truthy (1, true, etc.) and not an object, then this
// projection must be inclusive. If object, assume its $meta, $slice, etc.
if (isDefiningProjection(projection[prop]) && !!projection[prop]) {
if (projection[prop] != null && typeof projection[prop] === 'object') {
if (isPOJO(projection[prop])) {
return isInclusive(projection[prop]);
} else {
return !!projection[prop];
Expand Down
12 changes: 12 additions & 0 deletions test/helpers/projection.isExclusive.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const assert = require('assert');

require('../common'); // required for side-effect setup (so that the default driver is set-up)
const isExclusive = require('../../lib/helpers/projection/isExclusive');

describe('isExclusive', function() {
it('handles $elemMatch (gh-14893)', function() {
assert.strictEqual(isExclusive({ field: { $elemMatch: { test: new Date('2024-06-01') } }, otherProp: 1 }), false);
});
});
12 changes: 12 additions & 0 deletions test/helpers/projection.isInclusive.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const assert = require('assert');

require('../common'); // required for side-effect setup (so that the default driver is set-up)
const isInclusive = require('../../lib/helpers/projection/isInclusive');

describe('isInclusive', function() {
it('handles $elemMatch (gh-14893)', function() {
assert.strictEqual(isInclusive({ field: { $elemMatch: { test: new Date('2024-06-01') } }, otherProp: 1 }), true);
});
});

0 comments on commit c6bd31d

Please sign in to comment.