mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15: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) { | 		if (!key || (Array.isArray(key) && !key.length) || !Array.isArray(fields) || !fields.length) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 		fields = fields.filter(Boolean); | 		fields = fields.map(helpers.fieldToString).filter(Boolean); | ||||||
| 		if (!fields.length) { | 		if (!fields.length) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		const data = {}; | 		const data = {}; | ||||||
| 		fields.forEach((field) => { | 		fields.forEach((field) => { | ||||||
| 			field = helpers.fieldToString(field); |  | ||||||
| 			data[field] = ''; | 			data[field] = ''; | ||||||
| 		}); | 		}); | ||||||
| 		if (Array.isArray(key)) { | 		if (Array.isArray(key)) { | ||||||
|   | |||||||
| @@ -521,6 +521,7 @@ describe('Hash methods', () => { | |||||||
|  |  | ||||||
| 		it('should not error if fields is empty array', async () => { | 		it('should not error if fields is empty array', async () => { | ||||||
| 			await db.deleteObjectFields('someKey', []); | 			await db.deleteObjectFields('someKey', []); | ||||||
|  | 			await db.deleteObjectField('someKey', []); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should not error if key is undefined', (done) => { | 		it('should not error if key is undefined', (done) => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user