Move relative files out of magic URI, IP addresses start with digits
This commit is contained in:
parent
a6eb070cfa
commit
c17e8a2a9a
3 changed files with 23 additions and 25 deletions
|
@ -1642,8 +1642,12 @@ main (int argc,
|
||||||
|
|
||||||
if (execute)
|
if (execute)
|
||||||
result = midori_app_send_command (app, uris);
|
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);
|
result = midori_app_instance_send_uris (app, uris);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
result = midori_app_instance_send_new_browser (app);
|
result = midori_app_instance_send_new_browser (app);
|
||||||
|
|
||||||
|
@ -1823,7 +1827,16 @@ main (int argc,
|
||||||
while (uri != NULL)
|
while (uri != NULL)
|
||||||
{
|
{
|
||||||
item = katze_item_new ();
|
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);
|
katze_item_set_uri (item, uri_ready);
|
||||||
g_free (uri_ready);
|
g_free (uri_ready);
|
||||||
katze_array_add_item (_session, item);
|
katze_array_add_item (_session, item);
|
||||||
|
|
|
@ -294,8 +294,6 @@ gchar*
|
||||||
sokoke_magic_uri (const gchar* uri,
|
sokoke_magic_uri (const gchar* uri,
|
||||||
KatzeArray* search_engines)
|
KatzeArray* search_engines)
|
||||||
{
|
{
|
||||||
gchar* current_dir;
|
|
||||||
gchar* result;
|
|
||||||
gchar** parts;
|
gchar** parts;
|
||||||
gchar* search;
|
gchar* search;
|
||||||
const gchar* search_uri;
|
const gchar* search_uri;
|
||||||
|
@ -313,20 +311,13 @@ sokoke_magic_uri (const gchar* uri,
|
||||||
/* Add file:// if we have a local path */
|
/* Add file:// if we have a local path */
|
||||||
if (g_path_is_absolute (uri))
|
if (g_path_is_absolute (uri))
|
||||||
return g_strconcat ("file://", uri, NULL);
|
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? */
|
/* Do we have a protocol? */
|
||||||
if (g_strstr_len (uri, 8, "://"))
|
if (g_strstr_len (uri, 8, "://"))
|
||||||
return sokoke_idn_to_punycode (g_strdup (uri));
|
return sokoke_idn_to_punycode (g_strdup (uri));
|
||||||
|
|
||||||
/* Do we have a domain, ip address or localhost? */
|
/* Do we have a domain, ip address or localhost? */
|
||||||
|
if (g_ascii_isdigit (uri[0]))
|
||||||
|
return g_strconcat ("http://", uri, NULL);
|
||||||
search = NULL;
|
search = NULL;
|
||||||
if (!strchr (uri, ' ') &&
|
if (!strchr (uri, ' ') &&
|
||||||
((search = strchr (uri, ':')) || (search = 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 (!(parts[1][1] == '\0' && !g_ascii_isalpha (parts[1][0])))
|
||||||
if (!strchr (parts[0], ' ') && !strchr (parts[1], ' '))
|
if (!strchr (parts[0], ' ') && !strchr (parts[1], ' '))
|
||||||
if ((search = g_strconcat ("http://", uri, NULL)))
|
{
|
||||||
{
|
search = g_strconcat ("http://", uri, NULL);
|
||||||
g_strfreev (parts);
|
g_strfreev (parts);
|
||||||
return sokoke_idn_to_punycode (search);
|
return sokoke_idn_to_punycode (search);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_strfreev (parts);
|
g_strfreev (parts);
|
||||||
/* We don't want to search? So return early. */
|
/* We don't want to search? So return early. */
|
||||||
|
|
|
@ -54,8 +54,6 @@ test_input (const gchar* input,
|
||||||
static void
|
static void
|
||||||
magic_uri_uri (void)
|
magic_uri_uri (void)
|
||||||
{
|
{
|
||||||
gchar* a, *b;
|
|
||||||
|
|
||||||
test_input ("ftp://ftp.mozilla.org", "ftp://ftp.mozilla.org");
|
test_input ("ftp://ftp.mozilla.org", "ftp://ftp.mozilla.org");
|
||||||
test_input ("ftp://ftp.mozilla.org/pub", "ftp://ftp.mozilla.org/pub");
|
test_input ("ftp://ftp.mozilla.org/pub", "ftp://ftp.mozilla.org/pub");
|
||||||
test_input ("http://www.example.com", "http://www.example.com");
|
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 ("example.com", "http://example.com");
|
||||||
test_input ("www.google..com", "http://www.google..com");
|
test_input ("www.google..com", "http://www.google..com");
|
||||||
test_input ("/home/user/midori.html", "file:///home/user/midori.html");
|
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", "http://localhost");
|
||||||
test_input ("localhost:8000", "http://localhost:8000");
|
test_input ("localhost:8000", "http://localhost:8000");
|
||||||
test_input ("localhost/rss", "http://localhost/rss");
|
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", "http://192.168.1.1");
|
||||||
test_input ("192.168.1.1:8000", "http://192.168.1.1:8000");
|
test_input ("192.168.1.1:8000", "http://192.168.1.1:8000");
|
||||||
test_input ("file:///home/mark/foo/bar.html",
|
test_input ("file:///home/mark/foo/bar.html",
|
||||||
|
|
Loading…
Reference in a new issue