Skip to content

Commit

Permalink
Compare paths using utf8_collate_key() since paths are utf8-encoded.
Browse files Browse the repository at this point in the history
It fixes bug 1959854.
  • Loading branch information
Laurent Monin committed Jun 5, 2008
1 parent baf540a commit 3cf04e2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/collect.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static gint collection_list_sort_cb(gconstpointer a, gconstpointer b)
return 0;
break;
case SORT_PATH:
return CASE_SORT(cia->fd->path, cib->fd->path); /* FIXME: utf8_collate */
return utf8_compare(cia->fd->path, cib->fd->path, options->file_sort.case_sensitive);
break;
#ifdef HAVE_STRVERSCMP
case SORT_NUMBER:
Expand Down
2 changes: 1 addition & 1 deletion src/dupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ static gint dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *ra

if (mask & DUPE_MATCH_PATH)
{
if (strcmp(a->fd->path, b->fd->path) != 0) return FALSE;
if (utf8_compare(a->fd->path, b->fd->path, TRUE) != 0) return FALSE;
}
if (mask & DUPE_MATCH_NAME)
{
Expand Down
32 changes: 32 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,38 @@ gchar *utf8_validate_or_convert(const gchar *text)
return g_strdup(text);
}

gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
{
gchar *s1_key, *s2_key;
gchar *s1_t, *s2_t;
gint ret;

g_assert(g_utf8_validate(s1, -1, NULL));
g_assert(g_utf8_validate(s2, -1, NULL));

if (!case_sensitive)
{
s1_t = g_utf8_casefold(s1, -1);
s2_t = g_utf8_casefold(s2, -1);
}

s1_key = g_utf8_collate_key(s1_t, -1);
s2_key = g_utf8_collate_key(s2_t, -1);

ret = strcmp(s1_key, s2_key);

g_free(s1_key);
g_free(s2_key);

if (!case_sensitive)
{
g_free(s1_t);
g_free(s2_t);
}

return ret;
}

/* Borrowed from gtkfilesystemunix.c */
gchar *expand_tilde(const gchar *filename)
{
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@

gdouble get_zoom_increment(void);
gchar *utf8_validate_or_convert(const gchar *text);
gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive);
gchar *expand_tilde(const gchar *filename);

void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event);
Expand Down
2 changes: 1 addition & 1 deletion src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,7 @@ static gint search_result_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIt
return sort_matchdata_dimensions(fda, fdb);
break;
case SEARCH_COLUMN_PATH:
return CASE_SORT(fda->fd->path, fdb->fd->path); /* FIXME: utf8_collate */
return utf8_compare(fda->fd->path, fdb->fd->path, options->file_sort.case_sensitive);
break;
default:
break;
Expand Down

0 comments on commit 3cf04e2

Please sign in to comment.