From c17e8a2a9adcd87522ce599a4930453ef0767fc9 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 13 Aug 2009 23:55:15 +0200 Subject: [PATCH] Move relative files out of magic URI, IP addresses start with digits --- midori/main.c | 17 +++++++++++++++-- midori/sokoke.c | 23 +++++++---------------- tests/magic-uri.c | 8 +------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/midori/main.c b/midori/main.c index 6c277c5c..ffbf2b28 100644 --- a/midori/main.c +++ b/midori/main.c @@ -1642,8 +1642,12 @@ main (int argc, if (execute) result = midori_app_send_command (app, uris); - else if (uris) /* TODO: Open a tab per URI, seperated by pipes */ + else if (uris) + { + /* TODO: Open a tab per URI, seperated by pipes */ + /* FIXME: Handle relative files or magic URI here */ result = midori_app_instance_send_uris (app, uris); + } else result = midori_app_instance_send_new_browser (app); @@ -1823,7 +1827,16 @@ main (int argc, while (uri != NULL) { item = katze_item_new (); - uri_ready = sokoke_magic_uri (uri, NULL); + /* Construct an absolute path if the file is relative */ + if (g_file_test (uri, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) + { + gchar* current_dir = g_get_current_dir (); + uri_ready = g_strconcat ("file://", current_dir, + G_DIR_SEPARATOR_S, uri, NULL); + g_free (current_dir); + } + else + uri_ready = sokoke_magic_uri (uri, NULL); katze_item_set_uri (item, uri_ready); g_free (uri_ready); katze_array_add_item (_session, item); diff --git a/midori/sokoke.c b/midori/sokoke.c index 17abbde2..9b802290 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -294,8 +294,6 @@ gchar* sokoke_magic_uri (const gchar* uri, KatzeArray* search_engines) { - gchar* current_dir; - gchar* result; gchar** parts; gchar* search; const gchar* search_uri; @@ -313,20 +311,13 @@ sokoke_magic_uri (const gchar* uri, /* Add file:// if we have a local path */ if (g_path_is_absolute (uri)) return g_strconcat ("file://", uri, NULL); - /* Construct an absolute path if the file is relative */ - if (g_file_test (uri, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) - { - current_dir = g_get_current_dir (); - result = g_strconcat ("file://", current_dir, - G_DIR_SEPARATOR_S, uri, NULL); - g_free (current_dir); - return result; - } /* Do we have a protocol? */ if (g_strstr_len (uri, 8, "://")) return sokoke_idn_to_punycode (g_strdup (uri)); /* Do we have a domain, ip address or localhost? */ + if (g_ascii_isdigit (uri[0])) + return g_strconcat ("http://", uri, NULL); search = NULL; if (!strchr (uri, ' ') && ((search = strchr (uri, ':')) || (search = strchr (uri, '@'))) && @@ -339,11 +330,11 @@ sokoke_magic_uri (const gchar* uri, { if (!(parts[1][1] == '\0' && !g_ascii_isalpha (parts[1][0]))) if (!strchr (parts[0], ' ') && !strchr (parts[1], ' ')) - if ((search = g_strconcat ("http://", uri, NULL))) - { - g_strfreev (parts); - return sokoke_idn_to_punycode (search); - } + { + search = g_strconcat ("http://", uri, NULL); + g_strfreev (parts); + return sokoke_idn_to_punycode (search); + } } g_strfreev (parts); /* We don't want to search? So return early. */ diff --git a/tests/magic-uri.c b/tests/magic-uri.c index a771786d..db9ea4ee 100644 --- a/tests/magic-uri.c +++ b/tests/magic-uri.c @@ -54,8 +54,6 @@ test_input (const gchar* input, static void magic_uri_uri (void) { - gchar* a, *b; - test_input ("ftp://ftp.mozilla.org", "ftp://ftp.mozilla.org"); test_input ("ftp://ftp.mozilla.org/pub", "ftp://ftp.mozilla.org/pub"); test_input ("http://www.example.com", "http://www.example.com"); @@ -64,14 +62,10 @@ magic_uri_uri (void) test_input ("example.com", "http://example.com"); test_input ("www.google..com", "http://www.google..com"); test_input ("/home/user/midori.html", "file:///home/user/midori.html"); - a = g_get_current_dir (); - b = g_strconcat ("file://", a, G_DIR_SEPARATOR_S, "magic-uri.c", NULL); - g_free (a); - test_input ("magic-uri.c", b); - g_free (b); test_input ("localhost", "http://localhost"); test_input ("localhost:8000", "http://localhost:8000"); test_input ("localhost/rss", "http://localhost/rss"); + test_input ("10.0.0.1", "http://10.0.0.1"); test_input ("192.168.1.1", "http://192.168.1.1"); test_input ("192.168.1.1:8000", "http://192.168.1.1:8000"); test_input ("file:///home/mark/foo/bar.html", -- 2.39.5