diff options
author | Xan Lopez <xan@igalia.com> | 2012-08-07 21:28:21 +0800 |
---|---|---|
committer | Xan Lopez <xan@igalia.com> | 2012-08-07 21:28:21 +0800 |
commit | 57b873b72f880e85fc0abd7ae26d627e1578a028 (patch) | |
tree | 20992ed907b712693ad8b19a6a187508317033b2 /embed | |
parent | eea17ad5975842ba9a6c3e5ff0df08592ea2f5ee (diff) | |
download | gsoc2013-epiphany-57b873b72f880e85fc0abd7ae26d627e1578a028.tar.gz gsoc2013-epiphany-57b873b72f880e85fc0abd7ae26d627e1578a028.tar.zst gsoc2013-epiphany-57b873b72f880e85fc0abd7ae26d627e1578a028.zip |
ephy-web-view: do autosearch foo.bar strings where bar is not a TLD
Using the new SoupTLD methods. Had to split the non-search regexp in
two so that we can reuse its 'is this a domain?' bits. Ugly as hell,
but not worse than before... At least we have unit tests to catch
regressions.
https://bugzilla.gnome.org/show_bug.cgi?id=681022
Diffstat (limited to 'embed')
-rw-r--r-- | embed/ephy-embed-private.h | 7 | ||||
-rw-r--r-- | embed/ephy-web-view.c | 33 |
2 files changed, 35 insertions, 5 deletions
diff --git a/embed/ephy-embed-private.h b/embed/ephy-embed-private.h index b23c5a3e0..0fcc5007a 100644 --- a/embed/ephy-embed-private.h +++ b/embed/ephy-embed-private.h @@ -33,17 +33,18 @@ G_BEGIN_DECLS /* EphyWebView */ #define EPHY_WEB_VIEW_NON_SEARCH_REGEX "(" \ - "^localhost(\\.[^[:space:]]+)?(:\\d+)?(/.*)?$|" \ - "^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]$|" \ + "^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9](:[0-9]+)?.*$|" \ "^::[0-9a-f:]*$|" \ "^[0-9a-f:]+:[0-9a-f:]*$|" \ - "^[^\\.[:space:]]+\\.[^\\.[:space:]]+.*$|" \ "^https?://[^/\\.[:space:]]+.*$|" \ "^about:.*$|" \ "^data:.*$|" \ "^file:.*$" \ ")" +#define EPHY_WEB_VIEW_DOMAIN_REGEX "^localhost(\\.[^[:space:]]+)?(:\\d+)?(:[0-9]+)?(/.*)?$|" \ + "^[^\\.[:space:]]+\\.[^\\.[:space:]]+.*$|" + void ephy_web_view_set_visit_type (EphyWebView *view, EphyHistoryPageVisitType visit_type); EphyHistoryPageVisitType ephy_web_view_get_visit_type (EphyWebView *view); diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index accde2833..3ee698bc5 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -94,6 +94,7 @@ struct _EphyWebViewPrivate { /* Regex to figure out if we're dealing with a wanna-be URI */ GRegex *non_search_regex; + GRegex *domain_regex; GSList *hidden_popups; GSList *shown_popups; @@ -1063,11 +1064,16 @@ ephy_web_view_finalize (GObject *object) ephy_web_view_history_cleared_cb, EPHY_WEB_VIEW (object)); - if (priv->non_search_regex != NULL) { + if (priv->non_search_regex) { g_regex_unref (priv->non_search_regex); priv->non_search_regex = NULL; } + if (priv->domain_regex) { + g_regex_unref (priv->domain_regex); + priv->domain_regex = NULL; + } + ephy_web_view_popups_manager_reset (EPHY_WEB_VIEW (object)); g_free (priv->address); @@ -2694,6 +2700,9 @@ ephy_web_view_init (EphyWebView *web_view) priv->non_search_regex = g_regex_new (EPHY_WEB_VIEW_NON_SEARCH_REGEX, G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTEMPTY, NULL); + priv->domain_regex = g_regex_new (EPHY_WEB_VIEW_DOMAIN_REGEX, + G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTEMPTY, NULL); + priv->history_service = EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service (embed_shell)); priv->history_service_cancellable = g_cancellable_new (); @@ -2815,6 +2824,25 @@ ephy_web_view_new (void) return g_object_new (EPHY_TYPE_WEB_VIEW, NULL); } +static gboolean +is_public_domain (EphyWebView *view, const char *url) +{ + EphyWebViewPrivate *priv = view->priv; + + if (g_regex_match (priv->domain_regex, url, 0, NULL)) { + if (g_str_equal (url, "localhost")) + return TRUE; + + url = g_strstr_len (url, -1, "."); + if (!url || *url == '\0') + return FALSE; + + return soup_tld_domain_is_public_suffix (url); + } + + return FALSE; +} + /** * ephy_web_view_normalize_or_autosearch_url: * @view: an %EphyWebView @@ -2842,7 +2870,8 @@ ephy_web_view_normalize_or_autosearch_url (EphyWebView *view, const char *url) scheme == NULL && !ephy_embed_utils_address_is_existing_absolute_filename (url) && priv->non_search_regex && - !g_regex_match (priv->non_search_regex, url, 0, NULL)) { + !g_regex_match (priv->non_search_regex, url, 0, NULL) && + !is_public_domain (view, url)) { char *query_param, *url_search; url_search = g_settings_get_string (EPHY_SETTINGS_MAIN, |