Use common function and properly escape param to file command
Some checks failed
Tests / prove (push) Has been cancelled
Package and upload artifacts / build (push) Has been cancelled
Close inactive / close-inactive (push) Has been cancelled

This commit is contained in:
Jamie Cameron
2026-08-31 21:49:52 -07:00
parent 9807d97f0b
commit f11e1cb1e4

View File

@@ -7,25 +7,12 @@ $p = $ENV{'PATH_INFO'};
# Try to guess type from filename
if ($p =~ /\.([^\.\/]+)$/) {
$ext = lc($1);
&get_miniserv_config(\%miniserv);
open(MIME, "<$miniserv{'mimetypes'}");
while(<MIME>) {
s/#.*//g;
if (/(\S+)\s+(.*)/) {
foreach $e (split(/\s+/, $2)) {
if ($ext eq $e) {
$type = $1;
last;
}
}
}
}
close(MIME);
$type = &guess_mime_type($p);
}
if (!$type) {
# No idea .. use the 'file' command
if (`file "$p"` =~ /text|script/) {
my $out = &backquote_command("file ".quotemeta($p)." 2>/dev/null");
if ($out =~ /text|script/) {
$type = "text/plain";
}
else {