diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2021-01-04 13:02:20 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2021-01-05 12:52:14 -0500 |
commit | a282a571480133b01d26c87ca519debf3dc9a90c (patch) | |
tree | a416b085460462b2de0ae34d5cd9821c47079f4e /doc | |
parent | 6a28bd79b33f5830877b398f8f9be37ce93c1d38 (diff) | |
download | lighttpd-git-a282a571480133b01d26c87ca519debf3dc9a90c.tar.gz |
[doc] create-mime.conf.pl improve case handling
make create-mime.conf.pl more resilient to questionable edits
to /etc/mime.types
x-ref:
"lighttpd: does not start with media-types 1.1.0"
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=979232
Diffstat (limited to 'doc')
-rwxr-xr-x | doc/scripts/create-mime.conf.pl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/scripts/create-mime.conf.pl b/doc/scripts/create-mime.conf.pl index 29812838..fb6b3747 100755 --- a/doc/scripts/create-mime.conf.pl +++ b/doc/scripts/create-mime.conf.pl @@ -71,12 +71,21 @@ my %manual_conflicts_resolve = ( open MIMETYPES, "/etc/mime.types" or die "Can't open /etc/mime.types: $!"; my %extensions; +my %lcext; sub set { my ($extension, $mimetype) = @_; $extensions{$extension} = $mimetype; + $lcext{lc($extension)} = $extension; } sub add { my ($extension, $mimetype) = @_; + # lighttpd uses case-insensitive extension mapping to mime type. Still, + # preserve case of first ext seen if case-insensitive duplicates exist. + my $seen = $lcext{lc($extension)}; + if (defined($seen) && $seen ne $extension) { + # update @_ too for calls to set + $_[0] = $extension = $seen; + } my $have = $extensions{$extension}; my $r = $manual_conflicts_resolve{$extension}; @@ -110,6 +119,19 @@ sub add { } } + # non-vnd.* subtype wins over vnd.* subtype + if ($type eq $have_type) { + my $have_vnd = ($have_subtype =~ /^vnd\./); + if (($subtype =~ /^vnd\./) ^ $have_vnd) { + if ($have_vnd) { + return set @_; # overwrite + } + else { + return; # ignore + } + } + } + print STDERR "Duplicate mimetype: '${extension}' => '${mimetype}' (already have '${have}'), merging to 'application/octet-stream'\n"; set ($extension, 'application/octet-stream'); } else { |