Move relative files out of magic URI, IP addresses start with digits

This commit is contained in:
Christian Dywan 2009-08-13 23:55:15 +02:00
parent a6eb070cfa
commit c17e8a2a9a
3 changed files with 23 additions and 25 deletions

View file

@ -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,6 +1827,15 @@ main (int argc,
while (uri != NULL)
{
item = katze_item_new ();
/* 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);

View file

@ -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,8 +330,8 @@ 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)))
{
search = g_strconcat ("http://", uri, NULL);
g_strfreev (parts);
return sokoke_idn_to_punycode (search);
}

View file

@ -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",