diff --git a/configure.ac b/configure.ac
index e5e1d1a5..e852dcd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,7 +36,7 @@ AM_GLIB_GNU_GETTEXT
 
 GLIB_REQUIRED=2.42.0
 GLIB_MIN_REQUIRED=2.42
-GLIB_MAX_ALLOWED=2.42
+GLIB_MAX_ALLOWED=2.52
 
 GIO_REQUIRED=2.34.0
 GSETTINGS_DESKTOP_SCHEMAS_REQUIRED=0.1.0
diff --git a/src/terminal-util.c b/src/terminal-util.c
index ec4f506f..0c830e43 100644
--- a/src/terminal-util.c
+++ b/src/terminal-util.c
@@ -1192,7 +1192,7 @@ terminal_util_uri_fixup (const char *uri,
  */
 char *terminal_util_hyperlink_uri_label (const char *uri)
 {
-  char *unesc = NULL;
+  gs_free char *unesc = NULL;
   gboolean replace_hostname;
 
   if (uri == NULL)
@@ -1224,5 +1224,62 @@ char *terminal_util_hyperlink_uri_label (const char *uri)
     }
   }
 
-  return unesc;
+  return terminal_util_utf8_make_valid (unesc, -1);
+}
+
+/**
+ * terminal_util_utf8_make_valid:
+ *
+ * Just as g_utf8_make_valid().
+ *
+ * FIXME: Remove this wrapper once we require glib >= 2.52.
+ */
+gchar *
+terminal_util_utf8_make_valid (const gchar *str,
+                               gssize       len)
+{
+#if GLIB_CHECK_VERSION(2, 52, 0)
+  return g_utf8_make_valid (str, len);
+#else
+  /* copied from glib's g_utf8_make_valid() implementation */
+  GString *string;
+  const gchar *remainder, *invalid;
+  gsize remaining_bytes, valid_bytes;
+
+  g_return_val_if_fail (str != NULL, NULL);
+
+  if (len < 0)
+    len = strlen (str);
+
+  string = NULL;
+  remainder = str;
+  remaining_bytes = len;
+
+  while (remaining_bytes != 0)
+    {
+      if (g_utf8_validate (remainder, remaining_bytes, &invalid))
+	break;
+      valid_bytes = invalid - remainder;
+
+      if (string == NULL)
+	string = g_string_sized_new (remaining_bytes);
+
+      g_string_append_len (string, remainder, valid_bytes);
+      /* append U+FFFD REPLACEMENT CHARACTER */
+      g_string_append (string, "\357\277\275");
+
+      remaining_bytes -= valid_bytes + 1;
+      remainder = invalid + 1;
+    }
+
+  if (string == NULL)
+    return g_strndup (str, len);
+
+  g_string_append (string, remainder);
+  g_string_append_c (string, '\0');
+
+  g_assert (g_utf8_validate (string->str, -1, NULL));
+
+  return g_string_free (string, FALSE);
+#endif /* GLIB_CHECK_VERSION(2, 52, 0) */
 }
diff --git a/src/terminal-util.h b/src/terminal-util.h
index ce9cc3bd..040f4879 100644
--- a/src/terminal-util.h
+++ b/src/terminal-util.h
@@ -100,6 +100,9 @@ char *terminal_util_uri_fixup (const char *uri,
 
 char *terminal_util_hyperlink_uri_label (const char *str);
 
+gchar *terminal_util_utf8_make_valid (const gchar *str,
+                                      gssize       len) G_GNUC_MALLOC;
+
 G_END_DECLS
 
 #endif /* TERMINAL_UTIL_H */
