g_filename_from_uri rejects valid host names according to RFC 1123
The filename_from_uri now (2.82.2, in Fedora 41) rejects host names that start with digits. This violates RFC 1123 which updated the original RFC 952.
Reproducible: Always
Steps to Reproduce: 1.In python import gi from gi.repository import GLib GLib.filename_from_uri("file://123abc/home/user")
Actual Results: gi.repository.GLib.GError: g_convert_error: The hostname of the URI “file://123abc/home/user” is invalid (4)
Expected Results: Success, returning
('/home/user', hostname='123abc')
The following patch remedies the situation. There is a test for the incorrect behavior which I removed. Alternatively, one could change the hostname from 0123456789 to abc.0123456789.
diff -durp glib2-2.82.2-build/glib-2.82.2/glib/gconvert.c
glib2-2.82.2-build-save/glib-2.82.2/glib/gconvert.c
--- glib-2.82.2/glib/gconvert.c 2024-10-17 13:08:41.000000000 +0200
+++ glib-2.82.2/glib/gconvert.c 2024-11-03 16:51:28.986388308 +0100
@@ -1532,6 +1532,7 @@ hostname_validate (const char *hostname)
{
const char *p;
gunichar c, first_char, last_char;
+ gboolean no_domain = TRUE;
p = hostname;
if (*p == '\0')
@@ -1556,7 +1557,8 @@ hostname_validate (const char *hostname)
/* if that was the last label, check that it was a toplabel */
if (c == '\0' || (c == '.' && *p == '\0'))
- return is_asciialpha (first_char);
+ return no_domain || is_asciialpha (first_char);
+ no_domain = FALSE;
}
while (c == '.');
return FALSE;
Only in glib2-2.82.2-build-save/glib-2.82.2: redhat-linux-build
--- glib-2.82.2/glib/tests/uri.c-save 2024-11-03 17:05:55.490369860 +0100
+++ glib-2.82.2/glib/tests/uri.c 2024-11-03 17:10:26.527377057 +0100
@@ -154,7 +154,6 @@
{ "file:///c:/foo", "/c:/foo", NULL, 0 },
{ "file:////c:/foo", "//c:/foo", NULL, 0 },
#endif
- { "file://0123456789/", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
{ "file://ABCDEFGHIJKLMNOPQRSTUVWXYZ/", "/",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0 },
{ "file://abcdefghijklmnopqrstuvwxyz/", "/",
"abcdefghijklmnopqrstuvwxyz", 0 },
{ "file://-_.!~*'()/", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
Edited by Michael Catanzaro