fix: #12984, fix pids numeric sorting, handle non-integers

This commit is contained in:
Julian Lam
2025-01-10 15:15:06 -05:00
parent 3cf3f93a5e
commit 4dc740a20f
2 changed files with 9 additions and 2 deletions

View File

@@ -24,7 +24,14 @@ module.exports = function (Topics) {
throw new Error('[[error:invalid-pid]]');
}
pids.sort((a, b) => a - b);
if (pids.every(isFinite)) {
pids.sort((a, b) => a - b);
} else {
const pidsDatetime = (await db.sortedSetScores(`tid:${fromTid}:posts`, pids)).map(t => t || 0);
const map = pids.reduce((map, pid, idx) => map.set(pidsDatetime[idx], pid), new Map());
pidsDatetime.sort((a, b) => a - b);
pids = pidsDatetime.map(key => map.get(key));
}
const mainPid = pids[0];
if (!cid) {

View File

@@ -372,7 +372,7 @@ module.exports = function (Topics) {
timestampISO: replyPids.length ? utils.toISOString(pidMap[replyPids[0]].timestamp) : undefined,
};
replyPids.sort((a, b) => parseInt(a, 10) - parseInt(b, 10));
replyPids.sort((a, b) => pidMap[a].timestamp - pidMap[b].timestamp);
replyPids.forEach((replyPid) => {
const replyData = pidMap[replyPid];