diff --git a/src/dired.c b/src/dired.c index 84bf247..a2f388c 100644 --- a/src/dired.c +++ b/src/dired.c @@ -637,6 +637,20 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, if (!NILP (predicate) && NILP (call1 (predicate, name))) continue; + /* Reject entries where the encoded strings matched but the + decoded doesn't. Concretely, "a" should not match "a-ring" + on file system encoded using UTF-8 decomposed characters. */ + Lisp_Object zero = make_number (0); + if (SCHARS (file) <= SCHARS (name)) + { + Lisp_Object cmp + = Fcompare_strings (name, zero, make_number (SCHARS (file)), + file, zero, make_number (SCHARS (file)), + completion_ignore_case ? Qt : Qnil); + if (!EQ (cmp, Qt)) + continue; + } + /* Suitably record this match. */ matchcount += matchcount <= 1; @@ -650,7 +664,6 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, } else { - Lisp_Object zero = make_number (0); /* FIXME: This is a copy of the code in Ftry_completion. */ ptrdiff_t compare = min (bestmatchsize, SCHARS (name)); Lisp_Object cmp