From 7eb96eb3cbb0f29b7b09954308518caa99c3c5dc Mon Sep 17 00:00:00 2001 From: Haocen Xu Date: Sun, 17 May 2020 01:35:19 -0400 Subject: [PATCH] Avoid handling clipboard data item if it is not file type --- js/privatebin.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 23344dd8..56e1384b 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -3110,19 +3110,15 @@ jQuery.PrivateBin = (function($, RawDeflate) { */ function addClipboardEventHandler() { $(document).on('paste', function (event) { - if (TopNav.isAttachmentReadonly()) { - event.stopPropagation(); - event.preventDefault(); - return false; - } const items = (event.clipboardData || event.originalEvent.clipboardData).items; - for (let i = 0; i < items.length; ++i) { - if (items[i].kind === 'file') { - //Clear the file input: - $fileInput.wrap('
').closest('form').get(0).reset(); - $fileInput.unwrap(); - - readFileData(items[i].getAsFile()); + const lastItem = items[items.length - 1]; + if (lastItem.kind === 'file') { + if (TopNav.isAttachmentReadonly()) { + event.stopPropagation(); + event.preventDefault(); + return false; + } else { + readFileData(lastItem.getAsFile()); } } });