From a05632e3f447e8819457eff83aead42a10a51f8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Wed, 4 Jan 2023 13:53:21 -0500
Subject: [PATCH] misc: avoid dirty qrc urls

e.g. <a href="test" id="fuzzelement1">test</a> is invalid
and should not open qrc://components/test

Also fix editId on message edition and format in the reply row.

Change-Id: I570ddf18f6ba716e448e9fbadd558a4d04cdef1c
---
 src/app/commoncomponents/DataTransferMessageDelegate.qml | 2 +-
 src/app/commoncomponents/ReplyToRow.qml                  | 1 +
 src/app/commoncomponents/TextMessageDelegate.qml         | 2 +-
 src/app/mainview/components/AboutPopUp.qml               | 4 ++--
 src/app/mainview/components/EditContainer.qml            | 1 +
 src/app/mainview/components/FilePreview.qml              | 2 +-
 src/app/messagesadapter.cpp                              | 1 +
 src/app/settingsview/components/LogsView.qml             | 2 +-
 8 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/app/commoncomponents/DataTransferMessageDelegate.qml b/src/app/commoncomponents/DataTransferMessageDelegate.qml
index d8fad1738..d91203f10 100644
--- a/src/app/commoncomponents/DataTransferMessageDelegate.qml
+++ b/src/app/commoncomponents/DataTransferMessageDelegate.qml
@@ -202,7 +202,7 @@ Loader {
                                     dataTransferItem.hoveredLink = canOpen ?
                                                 ("file:///" + Body) : ""
                                     if (dataTransferItem.hoveredLink)
-                                        Qt.openUrlExternally(dataTransferItem.hoveredLink)
+                                        Qt.openUrlExternally(new Url(dataTransferItem.hoveredLink))
                                 }
                             }
                         }
diff --git a/src/app/commoncomponents/ReplyToRow.qml b/src/app/commoncomponents/ReplyToRow.qml
index 57d6833f9..7ec52fcc1 100644
--- a/src/app/commoncomponents/ReplyToRow.qml
+++ b/src/app/commoncomponents/ReplyToRow.qml
@@ -86,6 +86,7 @@ Item {
 
                 text: ReplyToBody
                 elide: Text.ElideRight
+                textFormat: Text.MarkdownText
 
                 color:  UtilsAdapter.luma(bubble.color) ?
                     JamiTheme.chatviewTextColorLight :
diff --git a/src/app/commoncomponents/TextMessageDelegate.qml b/src/app/commoncomponents/TextMessageDelegate.qml
index 03ea53541..05feb3388 100644
--- a/src/app/commoncomponents/TextMessageDelegate.qml
+++ b/src/app/commoncomponents/TextMessageDelegate.qml
@@ -83,7 +83,7 @@ SBSMessageBase {
             renderType: Text.NativeRendering
             textFormat: Text.MarkdownText
             onLinkHovered: root.hoveredLink = hoveredLink
-            onLinkActivated: Qt.openUrlExternally(hoveredLink)
+            onLinkActivated: Qt.openUrlExternally(new URL(hoveredLink))
             readOnly: true
             color: getBaseColor()
 
diff --git a/src/app/mainview/components/AboutPopUp.qml b/src/app/mainview/components/AboutPopUp.qml
index 722008ae7..57ca323a5 100644
--- a/src/app/mainview/components/AboutPopUp.qml
+++ b/src/app/mainview/components/AboutPopUp.qml
@@ -155,7 +155,7 @@ BaseModalDialog {
                 textFormat: TextEdit.RichText
                 selectByMouse: true
                 readOnly: true
-                onLinkActivated: Qt.openUrlExternally(link)
+                onLinkActivated: Qt.openUrlExternally(new Url(link))
 
                 TextMetrics {
                     id: textMetricsjamiDeclarationHyperText
@@ -189,7 +189,7 @@ BaseModalDialog {
                 textFormat: TextEdit.RichText
                 selectByMouse: true
                 readOnly: true
-                onLinkActivated: Qt.openUrlExternally(link)
+                onLinkActivated: Qt.openUrlExternally(new Url(link))
 
                 TextMetrics {
                     id: textMetricsjamiNoneWarrantyHyperText
diff --git a/src/app/mainview/components/EditContainer.qml b/src/app/mainview/components/EditContainer.qml
index 5f1360987..e1aa3d6fe 100644
--- a/src/app/mainview/components/EditContainer.qml
+++ b/src/app/mainview/components/EditContainer.qml
@@ -70,6 +70,7 @@ Rectangle {
                 }
 
                 text: metrics.elidedText
+                textFormat: Text.MarkdownText
                 color:  UtilsAdapter.luma(root.color) ?
                             JamiTheme.chatviewTextColorLight :
                             JamiTheme.chatviewTextColorDark
diff --git a/src/app/mainview/components/FilePreview.qml b/src/app/mainview/components/FilePreview.qml
index fe8f3fd94..30da38d8d 100644
--- a/src/app/mainview/components/FilePreview.qml
+++ b/src/app/mainview/components/FilePreview.qml
@@ -92,7 +92,7 @@ Component {
                                     ctxMenu.y = mouse.y
                                     ctxMenu.openMenu()
                                 } else {
-                                    Qt.openUrlExternally("file://" + Body)
+                                    Qt.openUrlExternally(new Url("file://" + Body))
                                 }
                             }
                         }
diff --git a/src/app/messagesadapter.cpp b/src/app/messagesadapter.cpp
index b61ad0719..598c4109a 100644
--- a/src/app/messagesadapter.cpp
+++ b/src/app/messagesadapter.cpp
@@ -180,6 +180,7 @@ MessagesAdapter::editMessage(const QString& convId, const QString& newBody, cons
         if (editId.isEmpty()) {
             return;
         }
+        set_editId("");
         lrcInstance_->getCurrentConversationModel()->editMessage(convId, newBody, editId);
     } catch (...) {
         qDebug() << "Exception during message edition:" << messageId;
diff --git a/src/app/settingsview/components/LogsView.qml b/src/app/settingsview/components/LogsView.qml
index 2073f9212..9afd5de75 100644
--- a/src/app/settingsview/components/LogsView.qml
+++ b/src/app/settingsview/components/LogsView.qml
@@ -220,7 +220,7 @@ Window {
                     autoAccelerator: true
 
                     onClicked: Qt.openUrlExternally(
-                                   "https://jami.net/bugs-and-improvements/")
+                                   new Url("https://jami.net/bugs-and-improvements/"))
                 }
             }
         }
-- 
GitLab