WebKitNetworkRequest* request;
WebKitDownload* download;
- hostname = midori_uri_parse (uri, &path);
+ hostname = midori_uri_parse_hostname (uri, &path);
temp_uri = NULL;
filename = NULL;
folder = NULL;
else
{
gchar* path;
- gchar* hostname = midori_uri_parse (uri, &path);
+ gchar* hostname = midori_uri_parse_hostname (uri, &path);
if (!strcmp (hostname, "userscripts.org")
&& (g_str_has_prefix (path, "/scripts/show/")
|| g_str_has_prefix (path, "/scripts/review/")))
label = midori_view_get_proxy_tab_label (view);
if (!midori_uri_is_blank (midori_view_get_display_uri (view))
- && (hostname = midori_uri_parse (midori_view_get_display_uri (view), NULL))
+ && (hostname = midori_uri_parse_hostname (midori_view_get_display_uri (view), NULL))
&& katze_object_get_enum (view, "load-status") == MIDORI_LOAD_FINISHED)
{
icon = midori_view_get_icon (view);
namespace Midori {
public class URI : Object {
- public static string parse (string? uri, out string path) {
- /* path may be null.
- If there's no hostname, the original URI is returned */
+ public static string? parse_hostname (string? uri, out string path) {
+ /* path may be null. */
if (uri == null)
return uri;
unowned string? hostname = uri.chr (-1, '/');
if (hostname == null || hostname[1] != '/'
|| hostname.chr (-1, ' ') != null)
- return uri;
+ return null;
hostname = hostname.offset (2);
if (&path != null) {
if ((path = hostname.chr (-1, '/')) != null)
if (uri.chr (-1, '/') != null && uri.chr (-1, ':') != null)
proto = uri.split ("://")[0];
string? path = null;
- string hostname = parse (uri, out path);
+ string? hostname = parse_hostname (uri, out path) ?? uri;
string encoded = hostname_to_ascii (hostname);
if (encoded != null) {
return (proto ?? "")
else if (!unescaped.validate ())
return uri;
string path;
- string hostname = parse (unescaped, out path);
+ string hostname = parse_hostname (unescaped, out path);
string decoded = hostname_to_unicode (hostname);
if (decoded != null)
return "http://" + decoded + path;
MidoriView* view)
{
const gchar* uri = webkit_web_frame_get_uri (web_frame);
- const gchar* hostname = midori_uri_parse (uri, NULL);
+ gchar* hostname = midori_uri_parse_hostname (uri, NULL);
gchar* message = g_strdup_printf (_("%s wants to save an HTML5 database."),
hostname && *hostname ? hostname : uri);
midori_view_add_info_bar (view, GTK_MESSAGE_QUESTION, message,
G_CALLBACK (midori_view_database_response_cb), database,
_("_Deny"), GTK_RESPONSE_REJECT, _("_Allow"), GTK_RESPONSE_ACCEPT,
NULL);
+ g_free (hostname);
g_free (message);
}
MidoriView* view)
{
const gchar* uri = webkit_web_frame_get_uri (web_frame);
- const gchar* hostname = midori_uri_parse (uri, NULL);
+ gchar* hostname = midori_uri_parse_hostname (uri, NULL);
gchar* message = g_strdup_printf (_("%s wants to know your location."),
hostname && *hostname ? hostname : uri);
midori_view_add_info_bar (view, GTK_MESSAGE_QUESTION,
message, G_CALLBACK (midori_view_location_response_cb), decision,
_("_Deny"), GTK_RESPONSE_REJECT, _("_Allow"), GTK_RESPONSE_ACCEPT,
NULL);
+ g_free (hostname);
g_free (message);
return TRUE;
}
if (settings && !katze_object_get_boolean (settings, "enable-dns-prefetching"))
return FALSE;
- if (!(hostname = midori_uri_parse (uri, NULL))
- || !strcmp (hostname, uri)
+ if (!(hostname = midori_uri_parse_hostname (uri, NULL))
|| g_hostname_is_ip_address (hostname)
|| !midori_uri_is_http (uri))
{
static void
magic_uri_uri (void)
{
+ const gchar* uri;
+ gchar* path;
+
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");
test_input ("foo:123@bar.baz", "http://foo:123@bar.baz");
/* test_input ("foo:f1o2o3@bar.baz", "http://f1o2o3:foo@bar.baz"); */
/* test_input ("foo:foo@bar.baz", "http://foo:foo@bar.baz"); */
+
+ uri = "http://bugs.launchpad.net/midori";
+ g_assert_cmpstr ("bugs.launchpad.net", ==, midori_uri_parse_hostname (uri, NULL));
+ uri = "https://bugs.launchpad.net/midori";
+ g_assert_cmpstr ("bugs.launchpad.net", ==, midori_uri_parse_hostname (uri, NULL));
+ g_assert_cmpstr ("bugs.launchpad.net", ==, midori_uri_parse_hostname (uri, &path));
+ g_assert_cmpstr ("/midori", ==, path);
+ uri = "http://айкидо.ru/users/kotyata";
+ g_assert_cmpstr ("айкидо.ru", ==, midori_uri_parse_hostname (uri, &path));
+ g_assert_cmpstr ("/users/kotyata", ==, path);
+ uri = "invalid:/uri.like/thing";
+ g_assert_cmpstr (NULL, ==, midori_uri_parse_hostname (uri, NULL));
+ uri = "invalid-uri.like:thing";
+ g_assert_cmpstr (NULL, ==, midori_uri_parse_hostname (uri, NULL));
}
static void