Use webkit_uri_for_display().
authorDaniel Carl <danielcarl@gmx.de>
Sun, 24 Mar 2019 23:07:52 +0000 (00:07 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 24 Mar 2019 23:17:46 +0000 (00:17 +0100)
Use this function for shown url for IDN homograph mitigation.

src/main.c
src/util.c

index 8127235..e54d7ac 100644 (file)
@@ -1351,13 +1351,13 @@ static void on_webview_load_changed(WebKitWebView *webview,
 
     switch (event) {
         case WEBKIT_LOAD_STARTED:
-            uri = util_sanitize_uri(webkit_web_view_get_uri(webview));
 #ifdef FEATURE_AUTOCMD
-            autocmd_run(c, AU_LOAD_STARTED, uri, NULL);
+            autocmd_run(c, AU_LOAD_STARTED, webkit_web_view_get_uri(webview), NULL);
 #endif
             /* update load progress in statusbar */
             c->state.progress = 0;
             vb_statusbar_update(c);
+            uri = util_sanitize_uri(webkit_web_view_get_uri(webview));
             set_title(c, uri);
             /* Make sure hinting is cleared before the new page is loaded.
              * Without that vimb would still be in hinting mode after hinting
@@ -1378,11 +1378,11 @@ static void on_webview_load_changed(WebKitWebView *webview,
              * or aborted the load will be commited. So this seems to be the
              * right place to remove the flag. */
             c->mode->flags &= ~FLAG_IGNORE_FOCUS;
-            uri = util_sanitize_uri(webkit_web_view_get_uri(webview));
 #ifdef FEATURE_AUTOCMD
-            autocmd_run(c, AU_LOAD_COMMITTED, uri, NULL);
+            autocmd_run(c, AU_LOAD_COMMITTED, webkit_web_view_get_uri(webview), NULL);
 #endif
             /* save the current URI in register % */
+            uri = util_sanitize_uri(webkit_web_view_get_uri(webview));
             vb_register_add(c, '%', uri);
             /* check if tls is on and the page is trusted */
             if (g_str_has_prefix(uri, "https://")) {
@@ -1407,7 +1407,7 @@ static void on_webview_load_changed(WebKitWebView *webview,
         case WEBKIT_LOAD_FINISHED:
             uri = util_sanitize_uri(webkit_web_view_get_uri(webview));
 #ifdef FEATURE_AUTOCMD
-            autocmd_run(c, AU_LOAD_FINISHED, uri, NULL);
+            autocmd_run(c, AU_LOAD_FINISHED, webkit_web_view_get_uri(webview), NULL);
 #endif
             c->state.progress = 100;
             if (strncmp(uri, "about:", 6)) {
index e22bb1d..a6fd4cc 100644 (file)
@@ -827,16 +827,24 @@ char *util_sanitize_uri(const char *uri_str)
 {
     SoupURI *uri;
     char *sanitized_uri;
+    char *for_display;
+
+#if WEBKIT_CHECK_VERSION(2, 24, 0)
+    for_display = webkit_uri_for_display(uri_str);
+#else
+    for_display = g_strdup(uri_str);
+#endif
 
     /* Sanitize the uri only in case there is a @ which might be the indicator
      * for credentials used in uri. */
-    if (!strchr(uri_str, '@')) {
-        return g_strdup(uri_str);
+    if (!strchr(for_display, '@')) {
+        return for_display;
     }
 
-    uri = soup_uri_new(uri_str);
+    uri           = soup_uri_new(for_display);
     sanitized_uri = soup_uri_to_string(uri, FALSE);
     soup_uri_free(uri);
+    g_free(for_display);
 
     return sanitized_uri;
 }