Subject: bug#11339: 24.1.50; read-{buffer,file-name}-completion-ignore-case fails on non-ascii

From: Eli Zaretskii <[email-masked]>
Date: Thu, 07 Nov 2019 20:12:31 +0200

> From: Stefan Monnier <[email-masked]>
> Cc: [email-masked],  [email-masked],  [email-masked]
> Date: Thu, 07 Nov 2019 11:27:50 -0500
> 
> >> I think the core of the bug is reproduced below:
> >> 
> >>     M-: (let ((completion-ignore-case t)) (try-completion "bah" '("bah" "bAh")))
> >> 
> >> this returns t instead of returning "bah".
> >> Probably an error in the handling of `matchcount` in `try-completion`.
> >
> > Are you sure?
> 
> I think so, yes.

The patch below fixes Stefan's simplified test case, but the original
problem is still unsolved: "C-x b ba TAB TAB" says "Sole completion".

What did I miss?

diff --git a/src/minibuf.c b/src/minibuf.c
index f6cf47f..2670211 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1363,7 +1363,13 @@ DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
 		    bestmatch = eltstring;
 		}
 	      if (bestmatchsize != SCHARS (eltstring)
-		  || bestmatchsize != matchsize)
+		  || bestmatchsize != matchsize
+		  || (completion_ignore_case
+		      && !EQ (Fcompare_strings (bestmatch, zero,
+						make_fixnum (compare),
+						eltstring, zero,
+						make_fixnum (compare), Qnil),
+			      Qt)))
 		/* Don't count the same string multiple times.  */
 		matchcount += matchcount <= 1;
 	      bestmatchsize = matchsize;