[epiphany] Automatically prefix existing absolute paths with file://



commit 398e670b1dd80cd0427a1db8a21dfc892bbe5eaf
Author: Gustavo Noronha Silva <gns gnome org>
Date:   Sat Mar 10 16:52:04 2012 -0300

    Automatically prefix existing absolute paths with file://
    
    https://bugzilla.gnome.org/show_bug.cgi?id=671792

 embed/ephy-embed-utils.c      |   12 +++++++++++-
 embed/ephy-embed-utils.h      |    9 +++++----
 embed/ephy-web-view.c         |    1 +
 tests/ephy-embed-utils-test.c |    1 +
 tests/ephy-web-view-test.c    |    2 ++
 5 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c
index e018424..70c8a6c 100644
--- a/embed/ephy-embed-utils.c
+++ b/embed/ephy-embed-utils.c
@@ -103,6 +103,13 @@ ephy_embed_utils_address_has_web_scheme (const char *address)
 	return has_web_scheme;
 }
 
+gboolean
+ephy_embed_utils_address_is_existing_absolute_filename (const char *address)
+{
+	return g_path_is_absolute (address) &&
+	       g_file_test (address, G_FILE_TEST_EXISTS);
+}
+
 char*
 ephy_embed_utils_normalize_address (const char *address)
 {
@@ -111,6 +118,9 @@ ephy_embed_utils_normalize_address (const char *address)
 
 	g_return_val_if_fail (address, NULL);
 
+	if (ephy_embed_utils_address_is_existing_absolute_filename (address))
+		return g_strconcat ("file://", address, NULL);
+
 	uri = soup_uri_new (address);
 
 	/* FIXME: if we are here we passed through the "should we
@@ -123,7 +133,7 @@ ephy_embed_utils_normalize_address (const char *address)
 	 * being the port. Ideally we should check if we have a
 	 * handler for the scheme, and since we'll fail for localhost
 	 * and IP, we'd fallback to loading it as a domain. */
-	if (!uri || 
+	if (!uri ||
 	    (uri && !g_strcmp0 (uri->scheme, "localhost")) ||
 	    (uri && g_hostname_is_ip_address (uri->scheme)))
 		effective_address = g_strconcat ("http://";, address, NULL);
diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h
index cb78900..4d8ded1 100644
--- a/embed/ephy-embed-utils.h
+++ b/embed/ephy-embed-utils.h
@@ -40,10 +40,11 @@ G_BEGIN_DECLS
 
 #define EPHY_WEBKIT_BACK_FORWARD_LIMIT 100
 
-char*    ephy_embed_utils_link_message_parse     (char       *message);
-gboolean ephy_embed_utils_address_has_web_scheme (const char *address);
-char*    ephy_embed_utils_normalize_address      (const char *address);
-gboolean ephy_embed_utils_url_is_empty           (const char *location);
+char*    ephy_embed_utils_link_message_parse                    (char       *message);
+gboolean ephy_embed_utils_address_has_web_scheme                (const char *address);
+gboolean ephy_embed_utils_address_is_existing_absolute_filename (const char *address);
+char*    ephy_embed_utils_normalize_address                     (const char *address);
+gboolean ephy_embed_utils_url_is_empty                          (const char *location);
 
 G_END_DECLS
 
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index f524997..c0b59db 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2417,6 +2417,7 @@ normalize_or_autosearch_url (EphyWebView *view, const char *url)
   /* If the string doesn't look like an URI, let's search it; */
   if (!ephy_embed_utils_address_has_web_scheme (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)) {
     char *query_param, *url_search;
diff --git a/tests/ephy-embed-utils-test.c b/tests/ephy-embed-utils-test.c
index 446cd80..669013c 100644
--- a/tests/ephy-embed-utils-test.c
+++ b/tests/ephy-embed-utils-test.c
@@ -70,6 +70,7 @@ static const SchemeTest tests_no_scheme[] = {
 };
 
 static const NormalizeTest tests_normalize[] = {
+  { "append_file_to_path", "/etc/passwd", "file:///etc/passwd" },
   { "append_http_to_domain", "gnome.org", "http://gnome.org"; },
   { "append_http_to_www", "www.gnome.org", "http://www.gnome.org"; },
   { "append_http_to_hostname", "gnome", "http://gnome"; },
diff --git a/tests/ephy-web-view-test.c b/tests/ephy-web-view-test.c
index 65a03eb..6afd0a5 100644
--- a/tests/ephy-web-view-test.c
+++ b/tests/ephy-web-view-test.c
@@ -174,6 +174,8 @@ static const RegexTest test_non_search_regex[] = {
   /* Searches */
   { "localhost localdomain:8080/home/", FALSE },
 
+  /* Relative paths should be searched */
+  { "./", FALSE },
 
   { "localhost", TRUE },
   { "localhost.localdomain", TRUE },



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