diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index b63f7826c..4fb14e51b 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -1361,12 +1361,8 @@ get_content_type (const char *basename, { /* Don't sniff zero-length files in order to avoid reading files * that appear normal but are not (eg: files in /proc and /sys) - * - * Note that we need to return text/plain here so that - * newly-created text files are opened by the text editor. - * See https://bugzilla.gnome.org/show_bug.cgi?id=755795 */ - return g_content_type_from_mime_type ("text/plain"); + return g_content_type_from_mime_type ("application/x-zerosize"); } #endif #ifdef S_ISSOCK diff --git a/gio/gosxcontenttype.m b/gio/gosxcontenttype.m index fad028038..4d7a650c7 100644 --- a/gio/gosxcontenttype.m +++ b/gio/gosxcontenttype.m @@ -419,6 +419,12 @@ g_content_type_from_mime_type (const gchar *mime_type) if (strcmp (mime_type, "text/plain") == 0) return g_strdup ("public.text"); + /* I don’t know of an appropriate equivalent for application/x-zerosize, but + * historically GLib has returned public.text for zero-sized files, so let’s + * continue doing that. */ + if (strcmp (mime_type, "application/x-zerosize") == 0) + return g_strdup ("public.text"); + /* Non standard type */ if (strcmp (mime_type, "application/x-executable") == 0) return g_strdup ("public.executable"); diff --git a/gio/tests/file.c b/gio/tests/file.c index 4fec7aa09..19f5842b5 100644 --- a/gio/tests/file.c +++ b/gio/tests/file.c @@ -3537,10 +3537,14 @@ test_query_zero_length_content_type (void) GFileIOStream *iostream; g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=755795"); - /* This is historic behaviour. See: + /* Historically, GLib used to explicitly consider zero-size files as text/plain, + * so they opened in a text editor. In 2.76, we changed that to application/x-zerosize, + * because that’s what xdgmime uses: * - https://gitlab.gnome.org/GNOME/glib/-/blob/2.74.0/gio/glocalfileinfo.c#L1360-1369 - * - https://bugzilla.gnome.org/show_bug.cgi?id=755795 */ - g_test_summary ("empty files should always be considered text/plain"); + * - https://bugzilla.gnome.org/show_bug.cgi?id=755795 + * - https://gitlab.gnome.org/GNOME/glib/-/issues/2777 + */ + g_test_summary ("empty files should always be considered application/x-zerosize"); empty_file = g_file_new_tmp ("empty-file-XXXXXX", &iostream, &error); g_assert_no_error (error); @@ -3557,7 +3561,7 @@ test_query_zero_length_content_type (void) g_assert_no_error (error); #ifndef __APPLE__ - g_assert_cmpstr (g_file_info_get_content_type (file_info), ==, "text/plain"); + g_assert_cmpstr (g_file_info_get_content_type (file_info), ==, "application/x-zerosize"); #else g_assert_cmpstr (g_file_info_get_content_type (file_info), ==, "public.text"); #endif