Node.js based forum software built for the modern web
fix: more tx fixes
Barış Soner Uşaklı5f0e877ec07e
diff --git a/install/package.json b/install/package.jsonindex 42efbdbf36..3730f287f0 100644--- a/install/package.json+++ b/install/package.json@@ -107,11 +107,11 @@"nodebb-plugin-emoji-android": "4.1.1","nodebb-plugin-link-preview": "2.2.5","nodebb-plugin-markdown": "13.2.4",- "nodebb-plugin-mentions": "4.8.18",+ "nodebb-plugin-mentions": "4.8.19","nodebb-plugin-spam-be-gone": "2.3.2","nodebb-plugin-web-push": "0.7.7","nodebb-rewards-essentials": "1.0.2",- "nodebb-theme-harmony": "2.2.69",+ "nodebb-theme-harmony": "2.2.70","nodebb-theme-lavender": "7.1.21","nodebb-theme-peace": "2.2.58","nodebb-theme-persona": "14.2.39",diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.jsindex 9134840860..5e84dbbcd9 100644--- a/public/src/modules/helpers.common.js+++ b/public/src/modules/helpers.common.js@@ -169,7 +169,7 @@ module.exports = function (utils, Benchpress, relative_path) {}function generateGroupDisplayName(group) {- return group.system ? group.displayName.replace(/-/g, ' ') : group.displayName;+ return group.system ? group.displayName.replace(/-/g, ' ') : helpers.txEscape(group.displayName);}// Groups helpers@@ -390,7 +390,9 @@ module.exports = function (utils, Benchpress, relative_path) {}function txEscape(text) {- return String(text).replace(/%/g, '%').replace(/,/g, ',');+ return String(text)+ .replace(/\[\[/g, '[[').replace(/\]\]/g, ']]')+ .replace(/,/g, ',').replace(/%/g, '%');}function uploadBasename(str, sep = '/') {diff --git a/public/src/modules/sort.js b/public/src/modules/sort.jsindex 17a1b437e7..833642c2c1 100644--- a/public/src/modules/sort.js+++ b/public/src/modules/sort.js@@ -7,7 +7,7 @@ define('sort', ['components'], function (components) {Sort.handleSort = function (field, gotoOnSave) {const threadSort = components.get('thread/sort');threadSort.find('i').removeClass('fa-check');- const currentSort = utils.params().sort || config[field];+ const currentSort = ajaxify.data.sortOption || config[field];const currentSetting = threadSort.find('a[data-sort="' + currentSort + '"]');currentSetting.find('i').addClass('fa-check');diff --git a/src/api/users.js b/src/api/users.jsindex 434d3921cf..5e30c45f27 100644--- a/src/api/users.js+++ b/src/api/users.js@@ -147,7 +147,10 @@ usersAPI.updateSettings = async function (caller, data) {};usersAPI.getStatus = async (caller, { uid }) => {- const status = await db.getObjectField(`user:${uid}`, 'status');+ let status = await db.getObjectField(`user:${uid}`, 'status');+ if (!user.allowedStatus.includes(status)) {+ status = 'offline';+ }return { status };};diff --git a/src/controllers/category.js b/src/controllers/category.jsindex 4e1df7acde..e0f1512909 100644--- a/src/controllers/category.js+++ b/src/controllers/category.js@@ -89,7 +89,8 @@ categoryController.get = async function (req, res, next) {const start = ((currentPage - 1) * userSettings.topicsPerPage) + topicIndex;const stop = start + userSettings.topicsPerPage - 1;- const sort = validSorts.includes(req.query.sort) ? req.query.sort : userSettings.categoryTopicSort;+ const selectedSort = String(req.query.sort || userSettings.categoryTopicSort);+ const sort = validSorts.includes(selectedSort) ? selectedSort : meta.config.categoryTopicSort;const categoryData = await categories.getCategoryById({uid: req.uid,@@ -148,7 +149,8 @@ categoryController.get = async function (req, res, next) {categoryData.topicIndex = topicIndex;categoryData.selectedTag = tagData.selectedTag;categoryData.selectedTags = tagData.selectedTags;- categoryData.sortOptionLabel = `[[topic:${validator.escape(String(sort)).replace(/_/g, '-')}]]`;+ categoryData.sortOption = sort;+ categoryData.sortOptionLabel = `[[topic:${sort.replace(/_/g, '-')}]]`;if (utils.isNumber(categoryData.cid) && !meta.config['feeds:disableRSS']) {categoryData.rssFeedUrl = `${url}/category/${categoryData.cid}.rss`;diff --git a/src/controllers/topics.js b/src/controllers/topics.jsindex 27ca733f6d..eeda0f2bbd 100644--- a/src/controllers/topics.js+++ b/src/controllers/topics.js@@ -80,7 +80,9 @@ topicsController.get = async function getTopic(req, res, next) {return helpers.redirect(res, `/topic/${tid}/${req.params.slug}${postIndex > topicData.postcount ? `/${topicData.postcount}` : ''}${generateQueryString(req.query)}`);}postIndex = Math.max(1, postIndex);- const sort = validSorts.includes(req.query.sort) ? req.query.sort : settings.topicPostSort;+ const selectedSort = String(req.query.sort || settings.topicPostSort);+ const sort = validSorts.includes(selectedSort) ? selectedSort : meta.config.topicPostSort;+const set = sort === 'most_votes' ? `tid:${tid}:posts:votes` : `tid:${tid}:posts`;const reverse = sort === 'newest_to_oldest' || sort === 'most_votes';@@ -118,7 +120,8 @@ topicsController.get = async function getTopic(req, res, next) {topicData.allowMultipleBadges = meta.config.allowMultipleBadges === 1;topicData.privateUploads = meta.config.privateUploads === 1;topicData.showPostPreviewsOnHover = meta.config.showPostPreviewsOnHover === 1;- topicData.sortOptionLabel = `[[topic:${validator.escape(String(sort)).replace(/_/g, '-')}]]`;+ topicData.sortOption = sort;+ topicData.sortOptionLabel = `[[topic:${sort.replace(/_/g, '-')}]]`;if (!meta.config['feeds:disableRSS']) {topicData.rssFeedUrl = `${relative_path}/topic/${topicData.tid}.rss`;if (req.loggedIn) {@@ -135,7 +138,7 @@ topicsController.get = async function getTopic(req, res, next) {user.getUserFields(topicData.uid, ['username', 'userslug']),topics.crossposts.get(topicData.tid),buildBreadcrumbs(topicData, settings.userLang),- addOldCategory(topicData, userPrivileges),+ addOldCategory(topicData, userPrivileges, settings.userLang),addTags(topicData, req, res, currentPage, postAtIndex),topics.increaseViewCount(req, tid),markAsRead(req, tid),@@ -224,11 +227,12 @@ async function buildBreadcrumbs(topicData, userLang) {topicData.breadcrumbs = parentCrumbs.concat(breadcrumbs);}-async function addOldCategory(topicData, userPrivileges) {+async function addOldCategory(topicData, userPrivileges, userLang) {if (userPrivileges.isAdminOrMod && topicData.oldCid) {topicData.oldCategory = await categories.getCategoryFields(topicData.oldCid, ['cid', 'name', 'icon', 'bgColor', 'color', 'slug']);+ topicData.oldCategory.name = await helpers.translateEscapedValue(topicData.oldCategory.name, userLang);}}diff --git a/src/messaging/data.js b/src/messaging/data.jsindex c55f944b44..2cdfa689dd 100644--- a/src/messaging/data.js+++ b/src/messaging/data.js@@ -8,6 +8,7 @@ const user = require('../user');const posts = require('../posts');const utils = require('../utils');const plugins = require('../plugins');+const translator = require('../translator');const intFields = ['mid', 'timestamp', 'edited', 'fromuid', 'roomId', 'deleted', 'system'];@@ -185,7 +186,7 @@ module.exports = function (Messaging) {}async function parseMessage(message, uid, roomId, isNew) {if (message.system) {- return validator.escape(String(message.content));+ return translator.escape(validator.escape(String(message.content)));} else if (!utils.isNumber(message.mid)) {return posts.sanitize(message.content);}diff --git a/src/messaging/rooms.js b/src/messaging/rooms.jsindex 17ce0f8059..0fdfd018a1 100644--- a/src/messaging/rooms.js+++ b/src/messaging/rooms.js@@ -14,6 +14,7 @@ const io = require('../socket.io');const cache = require('../cache');const cacheCreate = require('../cache/lru');const utils = require('../utils');+const translator = require('../translator');const roomUidCache = cacheCreate({name: 'chat-room-uids',@@ -48,7 +49,7 @@ module.exports = function (Messaging) {rooms.forEach((data) => {if (data) {db.parseIntFields(data, intFields, fields);- data.roomName = validator.escape(String(data.roomName || ''));+ data.roomName = translator.escape(validator.escape(String(data.roomName || '')));data.public = parseInt(data.public, 10) === 1;data.groupChat = data.userCount > 2;@@ -457,7 +458,11 @@ module.exports = function (Messaging) {}await db.setObjectField(`chat:room:${payload.roomId}`, 'roomName', payload.newName);- await Messaging.addSystemMessage(`room-rename, ${payload.newName.replace(',', ',')}`, payload.uid, payload.roomId);+ await Messaging.addSystemMessage(+ `room-rename, ${payload.newName.replace(/,/g, ',')}`,+ payload.uid,+ payload.roomId+ );plugins.hooks.fire('action:chat.renameRoom', {roomId: payload.roomId,diff --git a/src/socket.io/user/status.js b/src/socket.io/user/status.jsindex a00c1a6e9b..2adadac00b 100644--- a/src/socket.io/user/status.js+++ b/src/socket.io/user/status.js@@ -17,8 +17,7 @@ module.exports = function (SocketUser) {throw new Error('[[error:invalid-uid]]');}- const allowedStatus = ['online', 'offline', 'dnd', 'away'];- if (!allowedStatus.includes(status)) {+ if (!user.allowedStatus.includes(status)) {throw new Error('[[error:invalid-user-status]]');}diff --git a/src/user/data.js b/src/user/data.jsindex a282a146b6..b587c7987a 100644--- a/src/user/data.js+++ b/src/user/data.js@@ -44,6 +44,8 @@ module.exports = function (User) {'picture', 'cover:url',];+ User.allowedStatus = ['online', 'offline', 'dnd', 'away'];+User.guestData = {uid: 0,username: '[[global:guest]]',@@ -318,6 +320,9 @@ module.exports = function (User) {if (user.hasOwnProperty('status') && user.hasOwnProperty('lastonline')) {user.status = User.getStatus(user);+ if (!User.allowedStatus.includes(user.status)) {+ user.status = 'offline';+ }}if (user.hasOwnProperty('joindate')) {diff --git a/src/user/index.js b/src/user/index.jsindex df0fa13616..de1e079bd0 100644--- a/src/user/index.js+++ b/src/user/index.js@@ -100,7 +100,11 @@ User.getStatus = function (userData) {return 'offline';}const isOnline = (Date.now() - userData.lastonline) < (meta.config.onlineCutoff * 60000);- return isOnline ? (userData.status || 'online') : 'offline';+ let status = isOnline ? (userData.status || 'online') : 'offline';+ if (!User.allowedStatus.includes(status)) {+ status = 'offline';+ }+ return status;};User.getUidByUsername = async function (username) {diff --git a/src/views/partials/chats/composer.tpl b/src/views/partials/chats/composer.tplindex 48d78a89a4..1de046ced3 100644--- a/src/views/partials/chats/composer.tpl+++ b/src/views/partials/chats/composer.tpl@@ -7,7 +7,7 @@<button component="chat/upload/button" class="btn btn-ghost btn-sm d-flex p-2" type="button" title="[[global:upload]]" data-bs-toggle="tooltip"><i class="fa fa-fw fa-upload"></i></button>{{{ end }}}<div class="flex-grow-1 align-self-center">- <textarea component="chat/input" placeholder="{{{ if roomName }}}[[modules:chat.placeholder.message-room, {roomName}]]{{{ else }}}[[modules:chat.placeholder.mobile]]{{{ end }}}" class="bg-transparent text-body form-control chat-input mousetrap rounded-0 border-0 shadow-none px-1 py-0" style="min-height: 1.5rem;height:0;max-height:30vh;resize:none;"></textarea>+ <textarea component="chat/input" placeholder="{{{ if roomName }}}[[modules:chat.placeholder.message-room, {txEscape(roomName)}]]{{{ else }}}[[modules:chat.placeholder.mobile]]{{{ end }}}" class="bg-transparent text-body form-control chat-input mousetrap rounded-0 border-0 shadow-none px-1 py-0" style="min-height: 1.5rem;height:0;max-height:30vh;resize:none;"></textarea></div><div class="d-flex gap-1">{{{ each composerActions }}}