[polari] utils: Always include scheme in found URLs
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] utils: Always include scheme in found URLs
- Date: Wed, 18 Dec 2019 01:53:23 +0000 (UTC)
commit 278b24cf285031c3d140f0d2b2cc75508c5e1d1c
Author: Florian Müllner <fmuellner gnome org>
Date: Sun Dec 15 22:21:12 2019 +0100
utils: Always include scheme in found URLs
We already support a separate (display) name in order to linkify #channel
names. Start using it for regular URLs as well, so we can make sure that
the url property always includes the scheme.
https://gitlab.gnome.org/GNOME/polari/merge_requests/139
src/chatView.js | 8 ++------
src/utils.js | 7 +++++--
2 files changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 4ae8d18..c008ad3 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -1330,13 +1330,12 @@ var ChatView = GObject.registerClass({
let tag = this._createUrlTag(url.url);
this._view.get_buffer().tag_table.add(tag);
- let name = url.name ? url.name : url.url;
this._insertWithTags(iter,
- name, tags.concat(this._lookupTag('url'), tag));
+ url.name, tags.concat(this._lookupTag('url'), tag));
previews.push(new URLPreview({ uri: url.url, visible: true }));
- pos = url.pos + name.length;
+ pos = url.pos + url.name.length;
}
this._insertWithTags(iter, text.substr(pos), tags);
@@ -1424,9 +1423,6 @@ var ChatView = GObject.registerClass({
}
_createUrlTag(url) {
- if (!url.includes(':'))
- url = `http://${url}`;
-
let tag = new ButtonTag();
tag.connect('notify::hover', () => {
tag.foreground_rgba = tag.hover ? this._hoveredLinkColor : null;
diff --git a/src/utils.js b/src/utils.js
index 69ce5b2..1bd3b02 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -157,8 +157,11 @@ function _lookupPassword(schema, account, callback) {
// Return value: the list of match objects, as described above
function findUrls(str) {
let res = [], match;
- while ((match = _urlRegexp.exec(str)))
- res.push({ url: match[2], pos: match.index + match[1].length });
+ while ((match = _urlRegexp.exec(str))) {
+ let name = match[2];
+ let url = GLib.uri_parse_scheme(name) ? name : `http://${name}`;
+ res.push({ name, url, pos: match.index + match[1].length });
+ }
return res;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]