mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	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:
		| @@ -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)) { | ||||
|   | ||||
| @@ -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) => { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user