Case insensitive mimetype matching edge case
faure at kde.org
Wed Aug 5 13:33:12 PDT 2009
On Wednesday 20 May 2009, Alexander Larsson wrote:
> I got a bug report recently about a problem with case insensitive
> 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, 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...
$ kmimetypefinder foo.ps.gz
$ kmimetypefinder foo.PS.gz
> Not sure how to handle this. Maybe we should always do the insensitive
What was the use case for case-sensitive matches? Looking at the globs file...
Ah, I see one use case for it: *.C (text/x-c++src) vs *.c (text/x-csrc).
> and handle conflicts like we do multiple globs with the same
I don't think this would work. What we do is:
" If several globs matches, and sniffing gives a result we do:
" if sniffed prio >= 80, use sniffed type
" for glob_match in glob_matches:
" if glob_match is subclass or equal to sniffed_type, use glob_match
" If several globs matches, and sniffing fails, or doesn't help:
" fall back to the first glob match
But we lose the information that *.C matched and not *.c, therefore
we are looking at a random c-or-c++ file so adjusting glob priorities
wouldn't help, and sniffing doesn't help with such files either.
Seems to me that we should instead introduce an attribute for case-sensitivity:
<glob pattern="*.C" case-sensitive="true"/>
and do everything else case-insensitively.
David Faure, faure at kde.org, sponsored by Qt Software @ Nokia to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
More information about the xdg