From 1b467f6ca85185fc1d51bb029f80a0f6f6766d21 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 17 Jul 2018 16:02:37 +0100 Subject: [PATCH] fix pasting of plaintext content (prevent loads of
s) Fixes vector-im/riot-web#7043 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/rooms/MessageComposerInput.js | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index e4bd21cdf04..5885ae4e6ab 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -970,19 +970,21 @@ export default class MessageComposerInput extends React.Component { onPaste = (event: Event, change: Change, editor: Editor): Change => { const transfer = getEventTransfer(event); - if (transfer.type === "files") { - return this.props.onFilesPasted(transfer.files); - } - else if (transfer.type === "html") { - // FIXME: https://github.com/ianstormtaylor/slate/issues/1497 means - // that we will silently discard nested blocks (e.g. nested lists) :( - const fragment = this.html.deserialize(transfer.html); - if (this.state.isRichTextEnabled) { - return change.insertFragment(fragment.document); - } - else { - return change.insertText(this.md.serialize(fragment)); + switch (transfer.type) { + case 'files': + return this.props.onFilesPasted(transfer.files); + case 'html': { + // FIXME: https://github.com/ianstormtaylor/slate/issues/1497 means + // that we will silently discard nested blocks (e.g. nested lists) :( + const fragment = this.html.deserialize(transfer.html); + if (this.state.isRichTextEnabled) { + return change.insertFragment(fragment.document); + } else { + return change.insertText(this.md.serialize(fragment)); + } } + case 'text': + return change.insertText(transfer.text); } };