fix: convert to str than filter

prevent empty strings from getting passed to mongodb
https://github.com/NodeBB/NodeBB/issues/13007#issuecomment-2560503754
This commit is contained in:
Barış Soner Uşaklı
2024-12-23 20:29:42 -05:00
parent e71feeec1f
commit c69fa811e5
2 changed files with 2 additions and 2 deletions

View File

@@ -194,14 +194,13 @@ module.exports = function (module) {
if (!key || (Array.isArray(key) && !key.length) || !Array.isArray(fields) || !fields.length) {
return;
}
fields = fields.filter(Boolean);
fields = fields.map(helpers.fieldToString).filter(Boolean);
if (!fields.length) {
return;
}
const data = {};
fields.forEach((field) => {
field = helpers.fieldToString(field);
data[field] = '';
});
if (Array.isArray(key)) {

View File

@@ -521,6 +521,7 @@ describe('Hash methods', () => {
it('should not error if fields is empty array', async () => {
await db.deleteObjectFields('someKey', []);
await db.deleteObjectField('someKey', []);
});
it('should not error if key is undefined', (done) => {