Case insensitive mimetype matching edge case

Shaun McCance shaunm at
Wed Aug 5 19:27:22 PDT 2009

On Wed, 2009-05-20 at 15:20 +0200, Alexander Larsson wrote:
> I got a bug report[1] recently about a problem with case insensitive
> globs.
> The spec has this to say:
>  Applications MUST first try a case-sensitive match, then try again with
>  the filename converted to lower-case if that fails. This is so that 
>  main.C will be seen as a C++ file, but IMAGE.GIF will still use the
>  *.gif pattern. 
> Now, take the case of, foo.PS.GZ, and foo.PS.gz.
> The first matches .ps.gz and .gz case sensitively, picking the longer
> match.The second one does the same, but case insensitively.
> The third one however, matches .gz case insensitively only, so picks
> that instead of trying an insensitive match...
> Not sure how to handle this. Maybe we should always do the insensitive
> match and handle conflicts like we do multiple globs with the same
> extension?

Instead of doing the case-sensitive math first, couldn't
we do it last as a tie-breaker between matches of equal

Round 1:
  lowercase(foo.C) matches lowercase(*.C)
  lowercase(foo.C) matches lowercase(*.c)

We have two matches of equal length, so

Round 2:
  foo.C matches *.C
  foo.C does not match *.c

So *.C wins.

This would require doing the case-insensitive match by
lowercasing both the filename and the pattern.  I don't
know if that causes any problems.

It would also mean that a match for *.ext.c would win
over a match for *.C.  But since *.C seems to be the
only use case we have, I'm not sure that's an issue.


More information about the xdg mailing list