mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	fix: remove intFields hack and update db.parseIntFields to only parseInt if field value is a number
This commit is contained in:
		| @@ -11,11 +11,14 @@ if (!databaseName) { | ||||
| } | ||||
|  | ||||
| const primaryDB = require(`./${databaseName}`); | ||||
| const utils = require('../utils'); | ||||
|  | ||||
| primaryDB.parseIntFields = function (data, intFields, requestedFields) { | ||||
| 	intFields.forEach((field) => { | ||||
| 		if (!requestedFields || !requestedFields.length || requestedFields.includes(field)) { | ||||
| 			data[field] = parseInt(data[field], 10) || 0; | ||||
| 			data[field] = utils.isNumber(data[field]) ? | ||||
| 				parseInt(data[field], 10) || 0 : | ||||
| 				data[field]; | ||||
| 		} | ||||
| 	}); | ||||
| }; | ||||
|   | ||||
| @@ -59,19 +59,8 @@ module.exports = function (Posts) { | ||||
| }; | ||||
|  | ||||
| function modifyPost(post, fields) { | ||||
| 	const _intFields = [...intFields]; | ||||
|  | ||||
| 	if (post) { | ||||
| 		['pid', 'uid', 'tid'].forEach((prop) => { | ||||
| 			if ( | ||||
| 				post.hasOwnProperty(prop) && | ||||
| 				(activitypub.helpers.isUri(post[prop]) || validator.isUUID(String(post[prop]))) | ||||
| 			) { | ||||
| 				_intFields.splice(_intFields.indexOf(prop), 1); | ||||
| 			} | ||||
| 		}); | ||||
|  | ||||
| 		db.parseIntFields(post, _intFields, fields); | ||||
| 		db.parseIntFields(post, intFields, fields); | ||||
| 		if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { | ||||
| 			post.votes = post.upvotes - post.downvotes; | ||||
| 		} | ||||
|   | ||||
| @@ -95,13 +95,7 @@ function modifyTopic(topic, fields) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	const _intFields = [...intFields]; | ||||
| 	if (validator.isUUID(String(topic.tid))) { | ||||
| 		_intFields.splice(_intFields.indexOf('uid'), 1); | ||||
| 		_intFields.splice(_intFields.indexOf('tid'), 1); | ||||
| 		_intFields.splice(_intFields.indexOf('mainPid'), 1); | ||||
| 	} | ||||
| 	db.parseIntFields(topic, _intFields, fields); | ||||
| 	db.parseIntFields(topic, intFields, fields); | ||||
|  | ||||
| 	if (topic.hasOwnProperty('title')) { | ||||
| 		topic.titleRaw = topic.title; | ||||
|   | ||||
| @@ -246,9 +246,12 @@ module.exports = function (Topics) { | ||||
| 	}; | ||||
|  | ||||
| 	Topics.addPostToTopic = async function (tid, postData) { | ||||
| 		console.log('now in addPostToTopic', tid, postData); | ||||
| 		const mainPid = await Topics.getTopicField(tid, 'mainPid'); | ||||
| 		console.log(mainPid); | ||||
| 		if (!mainPid) { | ||||
| 			await Topics.setTopicField(tid, 'mainPid', postData.pid); | ||||
| 			console.log('what'); | ||||
| 		} else { | ||||
| 			const upvotes = parseInt(postData.upvotes, 10) || 0; | ||||
| 			const downvotes = parseInt(postData.downvotes, 10) || 0; | ||||
|   | ||||
| @@ -205,12 +205,7 @@ module.exports = function (User) { | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			const _intFields = [...intFields]; | ||||
|  | ||||
| 			if (activitypub.helpers.isUri(user.uid)) { | ||||
| 				_intFields.splice(_intFields.indexOf('uid'), 1); | ||||
| 			} | ||||
| 			db.parseIntFields(user, _intFields, requestedFields); | ||||
| 			db.parseIntFields(user, intFields, requestedFields); | ||||
|  | ||||
| 			if (user.hasOwnProperty('username')) { | ||||
| 				parseDisplayName(user, uidToSettings); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user