Trim trailing newlines from outgoing messages

This commit is contained in:
Chris Svenningsen 2020-11-11 14:56:20 -08:00 committed by GitHub
parent fef8c5b2f1
commit 98da8746e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -57,7 +57,8 @@ export const getTextFromOps = (ops: Array<DeltaOperation>): string =>
break;
}
}
return acc + textToAdd;
const textWithoutNewlines = textToAdd.replace(/\n+$/, '');
return acc + textWithoutNewlines;
}
if (insert.emoji) {
@ -93,7 +94,9 @@ export const getTextAndMentionsFromOps = (
break;
}
}
return acc + textToAdd;
const textWithoutNewlines = textToAdd.replace(/\n+$/, '');
return acc + textWithoutNewlines;
}
if (isInsertEmojiOp(op)) {

View file

@ -86,11 +86,18 @@ describe('getDeltaToRemoveStaleMentions', () => {
describe('getTextAndMentionsFromOps', () => {
describe('given only text', () => {
it('returns only text trimmed', () => {
const ops = [{ insert: ' The ' }, { insert: ' text ' }];
const ops = [{ insert: ' The ' }, { insert: ' text \n' }];
const [resultText, resultMentions] = getTextAndMentionsFromOps(ops);
assert.equal(resultText, 'The text');
assert.equal(resultMentions.length, 0);
});
it('returns trimmed of trailing newlines', () => {
const ops = [{ insert: ' The\ntext\n\n\n' }];
const [resultText, resultMentions] = getTextAndMentionsFromOps(ops);
assert.equal(resultText, 'The\ntext');
assert.equal(resultMentions.length, 0);
});
});
describe('given text, emoji, and mentions', () => {