Fix username links resulting in truncated chat messages (#11945)

* introduce MAX_MESSAGE_LENGTH constant

* add test

* fix path

* fix and tests

* fix typo in tests
This commit is contained in:
Matteo Pagliazzi
2020-03-04 11:49:14 +01:00
committed by GitHub
parent 75068ceb9e
commit 2ff9dfe965
9 changed files with 54 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ import { v4 as uuid } from 'uuid';
import { defaults } from 'lodash';
import removeMd from 'remove-markdown';
import baseModel from '../libs/baseModel';
import shared from '../../common';
const defaultSchema = () => ({
id: String,
@@ -113,14 +114,20 @@ export function setUserStyles (newMessage, user) {
}
}
// Sanitize an input message, separate from messageDefaults because
// it must run before mentions are highlighted
export function sanitizeText (msg) {
// Trim messages longer than the MAX_MESSAGE_LENGTH
return msg.substring(0, shared.constants.MAX_MESSAGE_LENGTH);
}
export function messageDefaults (msg, user, client, flagCount = 0, info = {}) {
const id = uuid();
const trimmedMessage = msg.substring(0, 3000);
const message = {
id,
_id: id,
text: trimmedMessage,
unformattedText: removeMd(trimmedMessage),
text: msg,
unformattedText: removeMd(msg),
info,
timestamp: Number(new Date()),
likes: {},