Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparently decode percent and punycode in URIs #377

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions core/suggestion-row.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions core/tab.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ();
Expand Down
2 changes: 1 addition & 1 deletion core/urlbar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
} }
Expand Down