From 3ce0f2f22cd01c8bb4b2ea75a8bcc8f01ebaed93 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 8 Nov 2016 17:06:09 +0100 Subject: [PATCH] feat(Utils/uri-tools): replace and escape html caracters like `<` --- tests/ui/modules/Linphone/Chat/Chat.qml | 4 ++-- tests/ui/modules/Linphone/Chat/Message.qml | 7 ++++++- tests/ui/scripts/Utils/uri-tools.js | 8 ++------ tests/ui/scripts/Utils/utils.js | 13 +++++++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/ui/modules/Linphone/Chat/Chat.qml b/tests/ui/modules/Linphone/Chat/Chat.qml index ac3182b7b..dd0e58f48 100644 --- a/tests/ui/modules/Linphone/Chat/Chat.qml +++ b/tests/ui/modules/Linphone/Chat/Chat.qml @@ -162,10 +162,10 @@ ColumnLayout { // TMP model: ListModel { - ListElement { $dateSection: 1465389121000; $outgoing: true; $timestamp: 1465389121000; $type: 'message'; $content: "click here" } + ListElement { $dateSection: 1465389121000; $outgoing: true; $timestamp: 1465389121000; $type: 'message'; $content: "www.google.fr" } ListElement { $dateSection: 1465389121000; $outgoing: true; $timestamp: 1465389121000; $type: 'message'; $content: "Contact mail" } ListElement { $dateSection: 1465389121000; $timestamp: 1465389133000; $type: 'event'; $content: 'incoming_call' } - ListElement { $dateSection: 1465389121000; $timestamp: 1465389439000; $type: 'message'; $content: 'Perfect! bg g vg gv v g v hgv gv gv jhb jh b jb jh hg vg cfcy f v u uyg f tf tf ft f tf t t fy ft f tu ty f rd rd d d uu gu y gg y f r dr ' } + ListElement { $dateSection: 1465389121000; $timestamp: 1465389439000; $type: 'message'; $content: 'Perfect! bg g vg gv v g v hgv gv gv jhb jh b jb jh hg vg cfcy f v u uyg f tf tf ft f tf t t fy ft f tu ty f rd rd d d uu gu y gg y f r dr ' } ListElement { $dateSection: 1465389121000; $timestamp: 1465389500000; $type: 'event'; $content: 'end_call' } ListElement { $dateSection: 1465994221000; $outgoing: true; $timestamp: 1465924321000; $type: 'message'; $content: 'You\'ve heard the expression, "Just believe it and it will come." Well, technically, that is true, however, \'believing\' is not just thinking that you can have it...' } ListElement { $dateSection: 1465994221000; $timestamp: 1465924391000; $type: 'event'; $content: 'lost_incoming_call' } diff --git a/tests/ui/modules/Linphone/Chat/Message.qml b/tests/ui/modules/Linphone/Chat/Message.qml index 2ce65eb84..4616c395d 100644 --- a/tests/ui/modules/Linphone/Chat/Message.qml +++ b/tests/ui/modules/Linphone/Chat/Message.qml @@ -1,6 +1,7 @@ import QtQuick 2.7 import Linphone.Styles 1.0 +import Utils 1.0 // =================================================================== @@ -36,12 +37,16 @@ Item { right: container.right } padding: ChatStyle.entry.message.padding - text: $content + text: Utils.encodeUrisToQmlFormat($content) wrapMode: Text.Wrap // Little fix. Text may disappear with scrolling. renderType: Text.NativeRendering + // See http://doc.qt.io/qt-5/qml-qtquick-text.html#textFormat-prop + // and http://doc.qt.io/qt-5/richtext-html-subset.html + textFormat: Text.StyledText + onLinkActivated: Qt.openUrlExternally(link) MouseArea { diff --git a/tests/ui/scripts/Utils/uri-tools.js b/tests/ui/scripts/Utils/uri-tools.js index 3163cbcca..6a4ea8209 100644 --- a/tests/ui/scripts/Utils/uri-tools.js +++ b/tests/ui/scripts/Utils/uri-tools.js @@ -2,6 +2,8 @@ // Library to deal with URI. // =================================================================== +.pragma library + // Level 0. ---------------------------------------------------------- var URI_PCT_ENCODED = '%[A-Fa-f\\d]{2}' @@ -84,12 +86,6 @@ var URI_REGEX = new RegExp(URI, 'g') // =================================================================== -function test () { - console.log('TOTO', URI_REGEX) - console.log('fe ef ef ef feff eff e fefefefe http://99w-w*w.test.com efeffe effe f ffe eef'.match(URI_REGEX)) -} -test() - /* TODO: Supports: URI-reference = URI / relative-ref diff --git a/tests/ui/scripts/Utils/utils.js b/tests/ui/scripts/Utils/utils.js index 755d1a843..9050ea058 100644 --- a/tests/ui/scripts/Utils/utils.js +++ b/tests/ui/scripts/Utils/utils.js @@ -2,6 +2,8 @@ // Contains many common helpers. // =================================================================== +.import 'uri-tools.js' as UriTools + // Load by default a window in the ui/views folder. // If options.isString is equals to true, a marshalling component can // be used. @@ -240,3 +242,14 @@ function genRandomNumberBetweenIntervals (intervals) { return n } + +// ------------------------------------------------------------------- + +function encodeUrisToQmlFormat (text) { + return text + .replace(//g, '>') + .replace(UriTools.URI_REGEX, function (match) { + return '' + match + '' + }) +}