Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Message_AllowedMaxSize fails for emoji sequences #10431

Merged
merged 17 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"emailreplyparser": "^0.0.5",
"file-type": "^7.7.1",
"filesize": "^3.6.1",
"grapheme-splitter": "^1.0.2",
"gridfs-stream": "^1.1.1",
"he": "^1.1.1",
"highlight.js": "^9.12.0",
Expand Down
18 changes: 15 additions & 3 deletions packages/rocketchat-lib/server/methods/sendMessage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import moment from 'moment';
import GraphemeSplitter from 'grapheme-splitter';

const splitter = new GraphemeSplitter();

Meteor.methods({
sendMessage(message) {
Expand Down Expand Up @@ -29,10 +32,19 @@ Meteor.methods({
message.ts = new Date();
}

if (message.msg && message.msg.length > RocketChat.settings.get('Message_MaxAllowedSize')) {
throw new Meteor.Error('error-message-size-exceeded', 'Message size exceeds Message_MaxAllowedSize', {
method: 'sendMessage'
if (message.msg) {
const adjustedMessage = message.msg.replace(/:\w+:/gm, (match) => {
if (RocketChat.emoji.list[match] !== undefined) {
return ' ';
}
return match;
});

if (splitter.countGraphemes(adjustedMessage) > RocketChat.settings.get('Message_MaxAllowedSize')) {
throw new Meteor.Error('error-message-size-exceeded', 'Message size exceeds Message_MaxAllowedSize', {
method: 'sendMessage'
});
}
}

const user = RocketChat.models.Users.findOneById(Meteor.userId(), {
Expand Down
12 changes: 11 additions & 1 deletion packages/rocketchat-ui/client/lib/chatMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import s from 'underscore.string';
import moment from 'moment';
import toastr from 'toastr';
import GraphemeSplitter from 'grapheme-splitter';

const splitter = new GraphemeSplitter();

this.ChatMessages = class ChatMessages {
init(node) {
Expand Down Expand Up @@ -554,7 +557,14 @@ this.ChatMessages = class ChatMessages {
}

isMessageTooLong(message) {
return message && message.length > this.messageMaxSize;
const adjustedMessage = message.replace(/:\w+:/gm, (match) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have this replace in two places... maybe use an export/import? (:

if (RocketChat.emoji.list[match] !== undefined) {
return ' ';
}
return match;
});

return message && splitter.countGraphemes(adjustedMessage) > this.messageMaxSize;
}

isEmpty() {
Expand Down