From f41aa097ce9f2bcf8b0bac271cbdc0539e597a42 Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Wed, 27 Nov 2019 14:40:30 +0100 Subject: [PATCH] Fixes Javascript crash when plain text is pasted as html (e. g. a phone number without html tags) into rich text field. Follow up for #2645. --- .../javascripts/app/lib/base/jquery.contenteditable.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js index 18c0319a4..09cf6532f 100644 --- a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js +++ b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js @@ -290,7 +290,11 @@ // E.g. Excel provides images of the spreadsheet along with HTML. // While some browsers make images available in clipboard as HTML, // sometimes wrapped in multiple nodes. - if($(clipboardData.getData('text/html')).text().trim().length == 0) { + + var rawHTML = clipboardData.getData('text/html') + var parsedHTML = jQuery(jQuery.parseHTML(rawHTML)) + + if(parsedHTML.text().trim().length == 0) { item = jQuery.grep(clipboardData.items, function(item){ return item.kind == 'file' && (item.type == 'image/png' || item.type == 'image/jpeg') })[0]