From 9e508e29400c2a5bb3003e91700c6c2d063f0b02 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Mon, 16 Sep 2019 10:21:06 +0200 Subject: [PATCH] Transparently decode percent and punycode in URIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Examples: - https://ja.wikipedia.org/wiki/アルマジロトカゲ (Armadillo girdled lizard) - https://Яндекс.рф (Yandex) - https://i❤tacos.ws/ --- core/suggestion-row.vala | 16 ++++++++++++++-- core/tab.vala | 10 +++++----- core/urlbar.vala | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/core/suggestion-row.vala b/core/suggestion-row.vala index 385c7f28b..45a361e06 100644 --- a/core/suggestion-row.vala +++ b/core/suggestion-row.vala @@ -74,10 +74,22 @@ namespace Midori { return Markup.escape_text (text); } - string? strip_uri_prefix (string uri) { + internal static string unescape_uri (string uri) { + // Percent-decode and decode punycode for user display + string[] parts = uri.split ("://", 2); + if (parts != null && parts[0] != null && parts[1] != null) { + string[] path = parts[1].split ("/", 2); + if (path != null && path[0] != null && path[1] != null) { + return parts[0] + "://" + Hostname.to_unicode (path[0]) + "/" + Uri.unescape_string (path[1]); + } + } + return uri; + } + + internal static string strip_uri_prefix (string uri) { bool is_http = uri.has_prefix ("http://") || uri.has_prefix ("https://"); if (is_http || uri.has_prefix ("file://")) { - string stripped_uri = uri.split ("://")[1]; + string stripped_uri = unescape_uri (uri); if (is_http && stripped_uri.has_prefix ("www.")) return stripped_uri.substring (4, -1); return stripped_uri; diff --git a/core/tab.vala b/core/tab.vala index c8b1437e3..187f978ff 100644 --- a/core/tab.vala +++ b/core/tab.vala @@ -214,7 +214,7 @@ namespace Midori { } var monitor = NetworkMonitor.get_default (); - string hostname = new Soup.URI (uri).host; + string hostname = Hostname.to_unicode (new Soup.URI (uri).host); string? title = null; string? message = null; if (!monitor.network_available) { @@ -261,7 +261,7 @@ namespace Midori { } public override void mouse_target_changed (WebKit.HitTestResult result, uint modifiers) { - link_uri = result.link_uri; + link_uri = result.link_uri != null ? SuggestionRow.strip_uri_prefix (result.link_uri) : null; } public override bool context_menu (WebKit.ContextMenu menu, @@ -348,11 +348,11 @@ namespace Midori { break; case WebKit.ScriptDialogType.CONFIRM: case WebKit.ScriptDialogType.BEFORE_UNLOAD_CONFIRM: - string hostname = new Soup.URI (uri).host; + string hostname = Hostname.to_unicode (new Soup.URI (uri).host); dialog.confirm_set_confirmed(((Browser)get_toplevel ()).prompt (hostname, dialog.get_message (), _("_Confirm")) != null); break; case WebKit.ScriptDialogType.PROMPT: - string hostname = new Soup.URI (uri).host; + string hostname = Hostname.to_unicode (new Soup.URI (uri).host); dialog.prompt_set_text(((Browser)get_toplevel ()).prompt (hostname, dialog.get_message (), _("_Confirm"), dialog.prompt_get_default_text ())); break; } @@ -380,7 +380,7 @@ namespace Midori { public override bool permission_request (WebKit.PermissionRequest permission) { if (permission is WebKit.GeolocationPermissionRequest) { - string hostname = new Soup.URI (uri).host; + string hostname = Hostname.to_unicode (new Soup.URI (uri).host); message.label = _("%s wants to know your location.").printf (hostname); } else if (permission is WebKit.NotificationPermissionRequest) { permission.allow (); diff --git a/core/urlbar.vala b/core/urlbar.vala index 5f4e866fd..15a98e2ff 100644 --- a/core/urlbar.vala +++ b/core/urlbar.vala @@ -22,7 +22,7 @@ namespace Midori { _uri = value; location = value; // Treat about:blank specially - text = blank ? "" : value; + text = blank ? "" : SuggestionRow.unescape_uri (value); set_position (-1); update_icon (); } }