[epiphany] ephy-web-view: ignore paths when deciding whether a URI has a TLD



commit 2801de37638347280be76be5c7e34b1237236b7d
Author: Xan Lopez <xan igalia com>
Date:   Tue Aug 14 18:09:08 2012 +0200

    ephy-web-view: ignore paths when deciding whether a URI has a TLD
    
    SoupTLD is not happy if we give it something like ".com/blah/blah".
    
    Add a unit test for this case too.

 embed/ephy-web-view.c      |   31 +++++++++++++++++++++++--------
 tests/ephy-web-view-test.c |    1 +
 2 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index f272265..5caa27a 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2853,20 +2853,35 @@ ephy_web_view_new (void)
 static gboolean
 is_public_domain (EphyWebView *view, const char *url)
 {
+  SoupURI *soup_uri;
+  gboolean retval = FALSE;
+  const char *host = NULL;
   EphyWebViewPrivate *priv = view->priv;
 
-  if (g_regex_match (priv->domain_regex, url, 0, NULL)) {
-    if (g_str_equal (url, "localhost"))
-      return TRUE;
+  soup_uri = soup_uri_new (url);
+  if (!soup_uri) {
+    char *effective_url = g_strconcat ("http://";, url, NULL);
+    soup_uri = soup_uri_new (effective_url);
+    g_free (effective_url);
+  }
+  g_return_val_if_fail (soup_uri, FALSE);
+
+  host = soup_uri->host;
 
-    url = g_strrstr (url, ".");
-    if (!url || *url == '\0')
-      return FALSE;
+  if (g_regex_match (priv->domain_regex, host, 0, NULL)) {
+    if (g_str_equal (host, "localhost"))
+      retval = TRUE;
+    else {
+      host = g_strrstr (host, ".");
 
-    return soup_tld_domain_is_public_suffix (url);
+      if (host && *host != '\0')
+        retval = soup_tld_domain_is_public_suffix (host);
+    }
   }
 
-  return FALSE;
+  soup_uri_free (soup_uri);
+
+  return retval;
 }
 
 /**
diff --git a/tests/ephy-web-view-test.c b/tests/ephy-web-view-test.c
index bc41fff..29739b1 100644
--- a/tests/ephy-web-view-test.c
+++ b/tests/ephy-web-view-test.c
@@ -283,6 +283,7 @@ static struct {
 } normalize_or_autosearch[] = {
   { "google.com", "http://google.com"; },
   { "http://google.com";, "http://google.com"; },
+  { "http://google.com/this/is/a/path";, "http://google.com/this/is/a/path"; },
   { "search", "http://www.google.com/search?q=search&ie=UTF-8&oe=UTF-8"; },
   { "search.me", "http://search.me"; },
   { "lala.lala", "http://www.google.com/search?q=lala%2Elala&ie=UTF-8&oe=UTF-8"; },



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]