From 9fb5ef60d43ae1a052967c6fc7aa3419dc1a3cc4 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sun, 13 Jun 2021 14:23:13 +0000 Subject: [PATCH] Image uploader mime filter uses urls but doesn't check them (#2855) Co-authored-by: pajlada --- CHANGELOG.md | 1 + src/widgets/helper/ResizingTextEdit.cpp | 26 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaaf842b..f28d192e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Minor: Added a link to accounts page in settings to "You need to be logged in to send messages" message. (#2862) - Minor: Switch to Twitch v2 emote API for animated emote support. (#2863) - Bugfix: Fixed FFZ emote links for global emotes (#2807, #2808) +- Bugfix: Fixed pasting text with URLs included (#1688, #2855) - Bugfix: Fix reconnecting when IRC write connection is lost (#1831, #2356, #2850) - Bugfix: Fixed bit emotes not loading in some rare cases. (#2856) diff --git a/src/widgets/helper/ResizingTextEdit.cpp b/src/widgets/helper/ResizingTextEdit.cpp index b89a45f4..56c60a72 100644 --- a/src/widgets/helper/ResizingTextEdit.cpp +++ b/src/widgets/helper/ResizingTextEdit.cpp @@ -5,6 +5,7 @@ #include "singletons/Settings.hpp" #include +#include namespace chatterino { @@ -264,14 +265,33 @@ bool ResizingTextEdit::canInsertFromMimeData(const QMimeData *source) const void ResizingTextEdit::insertFromMimeData(const QMimeData *source) { - if (source->hasImage() || source->hasUrls()) + if (source->hasImage()) { this->imagePasted.invoke(source); + return; } - else + else if (source->hasUrls()) { - insertPlainText(source->text()); + bool hasUploadable = false; + auto mimeDb = QMimeDatabase(); + for (const QUrl url : source->urls()) + { + QMimeType mime = mimeDb.mimeTypeForUrl(url); + if (mime.name().startsWith("image")) + { + hasUploadable = true; + break; + } + } + + if (hasUploadable) + { + this->imagePasted.invoke(source); + return; + } } + + insertPlainText(source->text()); } QCompleter *ResizingTextEdit::getCompleter() const