From 30bbf529ad3073fd449c7f9331a889b114fad1e1 Mon Sep 17 00:00:00 2001 From: Wynn Wolf Arbor Date: Sat, 28 Mar 2020 15:10:55 +0100 Subject: Add OSC 8 hyperlink support This commit adds support for the OSC 8 hyperlink escape sequence [1]. As this is not a mature feature and there seem to be outstanding security concerns [2], the setting that controls whether or not OSC 8 is interpreted is disabled by default. Just like gnome-terminal, weltschmerz will display a tooltip with the canonicalized URI when hovering over a hyperlink. [1] https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda [2] https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#security --- utils.vala | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 utils.vala (limited to 'utils.vala') diff --git a/utils.vala b/utils.vala new file mode 100644 index 0000000..845728b --- /dev/null +++ b/utils.vala @@ -0,0 +1,27 @@ +class Utils { + public static string? normalize_uri(string? uri) { + if (uri == null) + return null; + + string? u = Uri.unescape_string(uri, null); + + if (u == null) + u = uri; + + if (u.has_prefix("ftp://") || u.has_prefix("http://") || u.has_prefix("https://")) { + int a = u.index_of("/", 0) + 2; // character after second slash + int b = u.index_of("/", a); // next slash after hostname... + if (b < 0) + b = u.length; // ... or end of string + + string hostname = u.slice(a, b); + string? canon = Hostname.to_unicode(hostname); + + if (canon != null && hostname != canon) { + u = u.splice(a, b, canon); + } + } + + return u; + } +} -- cgit v1.2.3-2-gb3c3