From 20ae4b46d476915484ace6c982cfc99cd2602cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 30 Jul 2020 12:02:31 +0400 Subject: [PATCH] uri: do not add ipv6 brackets on non-ip host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The heuristic is a bit too agressive, as we may have hostname with %-encoded ':' (as shown in GVfs URI tests). Add an extra test to check :-decoding as well. Signed-off-by: Marc-André Lureau --- glib/guri.c | 2 +- glib/tests/uri.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/glib/guri.c b/glib/guri.c index 6179ea01d..cffed414c 100644 --- a/glib/guri.c +++ b/glib/guri.c @@ -1383,7 +1383,7 @@ g_uri_join_internal (GUriFlags flags, g_string_append_c (str, '@'); } - if (strchr (host, ':')) + if (strchr (host, ':') && g_hostname_is_ip_address (host)) { g_string_append_c (str, '['); if (encoded) diff --git a/glib/tests/uri.c b/glib/tests/uri.c index 70cee76e9..83279747a 100644 --- a/glib/tests/uri.c +++ b/glib/tests/uri.c @@ -669,6 +669,9 @@ static const UriAbsoluteTest absolute_tests[] = { { "http://:@host", { "http", ":", "host", -1, "", NULL, NULL } }, + { "scheme://foo%3Abar._webdav._tcp.local", + { "scheme", NULL, "foo:bar._webdav._tcp.local", -1, "", NULL, NULL} + }, /* IPv6 scope ID parsing (both correct and incorrect) */ { "http://[fe80::dead:beef%em1]/", @@ -1410,6 +1413,10 @@ test_uri_join (void) g_assert_cmpstr (uri, ==, "scheme://user%01:pass%02;authparams%03@[::192.9.5.5]:9876/path?query#fragment"); g_free (uri); + + uri = g_uri_join (G_URI_FLAGS_NONE, "scheme", NULL, "foo:bar._webdav._tcp.local", -1, "", NULL, NULL); + g_assert_cmpstr (uri, ==, "scheme://foo%3Abar._webdav._tcp.local"); + g_free (uri); } int