mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-19 07:08:54 +02:00
Don't assume filenames are UTF-8.
* xdgmime/xdgmimecache.c: * xdgmime/xdgmimeglob.c: Don't assume filenames are UTF-8. svn path=/trunk/; revision=7784
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
2009-01-08 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
Bug 565484 – g_content_type_guess passes non-UTF8 text to XDG
|
||||||
|
functions in non-UTF8 locale
|
||||||
|
|
||||||
|
* xdgmime/xdgmimecache.c:
|
||||||
|
* xdgmime/xdgmimeglob.c: Don't assume filenames are UTF-8.
|
||||||
|
|
||||||
2009-01-08 Matthias Clasen <mclasen@redhat.com>
|
2009-01-08 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* xdgmime/test-mime.c: Make tests work with current shared-mime-info.
|
* xdgmime/test-mime.c: Make tests work with current shared-mime-info.
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -439,7 +440,7 @@ static int
|
|||||||
cache_glob_node_lookup_suffix (XdgMimeCache *cache,
|
cache_glob_node_lookup_suffix (XdgMimeCache *cache,
|
||||||
xdg_uint32_t n_entries,
|
xdg_uint32_t n_entries,
|
||||||
xdg_uint32_t offset,
|
xdg_uint32_t offset,
|
||||||
xdg_unichar_t *file_name,
|
const char *file_name,
|
||||||
int len,
|
int len,
|
||||||
int ignore_case,
|
int ignore_case,
|
||||||
MimeWeight mime_types[],
|
MimeWeight mime_types[],
|
||||||
@@ -456,7 +457,7 @@ cache_glob_node_lookup_suffix (XdgMimeCache *cache,
|
|||||||
|
|
||||||
character = file_name[len - 1];
|
character = file_name[len - 1];
|
||||||
if (ignore_case)
|
if (ignore_case)
|
||||||
character = _xdg_ucs4_to_lower (character);
|
character = tolower (character);
|
||||||
|
|
||||||
assert (character != 0);
|
assert (character != 0);
|
||||||
|
|
||||||
@@ -511,11 +512,11 @@ cache_glob_node_lookup_suffix (XdgMimeCache *cache,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cache_glob_lookup_suffix (xdg_unichar_t *file_name,
|
cache_glob_lookup_suffix (const char *file_name,
|
||||||
int len,
|
int len,
|
||||||
int ignore_case,
|
int ignore_case,
|
||||||
MimeWeight mime_types[],
|
MimeWeight mime_types[],
|
||||||
int n_mime_types)
|
int n_mime_types)
|
||||||
{
|
{
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
@@ -557,7 +558,6 @@ cache_glob_lookup_file_name (const char *file_name,
|
|||||||
MimeWeight mimes[10];
|
MimeWeight mimes[10];
|
||||||
int n_mimes = 10;
|
int n_mimes = 10;
|
||||||
int i;
|
int i;
|
||||||
xdg_unichar_t *ucs4;
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
assert (file_name != NULL && n_mime_types > 0);
|
assert (file_name != NULL && n_mime_types > 0);
|
||||||
@@ -567,12 +567,11 @@ cache_glob_lookup_file_name (const char *file_name,
|
|||||||
if (n > 0)
|
if (n > 0)
|
||||||
return n;
|
return n;
|
||||||
|
|
||||||
ucs4 = _xdg_convert_to_ucs4 (file_name, &len);
|
len = strlen (file_name);
|
||||||
n = cache_glob_lookup_suffix (ucs4, len, FALSE, mimes, n_mimes);
|
n = cache_glob_lookup_suffix (file_name, len, FALSE, mimes, n_mimes);
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
n = cache_glob_lookup_suffix (ucs4, len, TRUE, mimes, n_mimes);
|
n = cache_glob_lookup_suffix (file_name, len, TRUE, mimes, n_mimes);
|
||||||
free(ucs4);
|
|
||||||
|
|
||||||
/* Last, try fnmatch */
|
/* Last, try fnmatch */
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#ifndef FALSE
|
#ifndef FALSE
|
||||||
#define FALSE (0)
|
#define FALSE (0)
|
||||||
@@ -297,7 +298,7 @@ typedef struct {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
_xdg_glob_hash_node_lookup_file_name (XdgGlobHashNode *glob_hash_node,
|
_xdg_glob_hash_node_lookup_file_name (XdgGlobHashNode *glob_hash_node,
|
||||||
xdg_unichar_t *file_name,
|
const char *file_name,
|
||||||
int len,
|
int len,
|
||||||
int ignore_case,
|
int ignore_case,
|
||||||
MimeWeight mime_types[],
|
MimeWeight mime_types[],
|
||||||
@@ -312,7 +313,7 @@ _xdg_glob_hash_node_lookup_file_name (XdgGlobHashNode *glob_hash_node,
|
|||||||
|
|
||||||
character = file_name[len - 1];
|
character = file_name[len - 1];
|
||||||
if (ignore_case)
|
if (ignore_case)
|
||||||
character = _xdg_ucs4_to_lower(character);
|
character = tolower(character);
|
||||||
|
|
||||||
for (node = glob_hash_node; node && character >= node->character; node = node->next)
|
for (node = glob_hash_node; node && character >= node->character; node = node->next)
|
||||||
{
|
{
|
||||||
@@ -392,15 +393,13 @@ _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ucs4 = _xdg_convert_to_ucs4 (file_name, &len);
|
len = strlen (file_name);
|
||||||
n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, ucs4, len, FALSE,
|
n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, FALSE,
|
||||||
mimes, n_mimes);
|
mimes, n_mimes);
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, ucs4, len, TRUE,
|
n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, TRUE,
|
||||||
mimes, n_mimes);
|
mimes, n_mimes);
|
||||||
free(ucs4);
|
|
||||||
|
|
||||||
/* FIXME: Not UTF-8 safe */
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
{
|
{
|
||||||
for (list = glob_hash->full_list; list && n < n_mime_types; list = list->next)
|
for (list = glob_hash->full_list; list && n < n_mime_types; list = list->next)
|
||||||
|
Reference in New Issue
Block a user