Browse Source

Ticket #4423 : Détecter aussi la compression zip lorsque le mime-type

n’est pas application/zip, mais que le mode RAW de finfo_file l’indique pourtant (merci @James)
remotes/checkIfPRContentChanged-1652436787196885812/master
Matthieu Marcillaud 10 months ago
parent
commit
bf17ff2384
  1. 22
      src/AbstractArchiver.php

22
src/AbstractArchiver.php

@ -13,9 +13,12 @@ use RecursiveIteratorIterator;
*/
abstract class AbstractArchiver implements ArchiverInterface
{
/** @var array<string, string> Mode de compression connus */
/** @var array<string, string> Mode de compression connus, d’après mime-type */
protected const COMPRESSIONS_CONNUES = ['zip' => 'zip', 'x-tar' => 'tar', 'gzip' => 'tgz'];
/** @var array<string, string> Mode de compression connus, sur raw mime-type */
protected const COMPRESSIONS_CONNUES_RAW = ['Zip archive data' => 'zip'];
/** @var int Dernier code d'erreur */
protected int $code_erreur = 0;
@ -139,9 +142,10 @@ abstract class AbstractArchiver implements ArchiverInterface
$file_mime_type = '';
if (file_exists($this->fichier_archive)) {
$finfo = finfo_open(FILEINFO_MIME);
$finfo = finfo_open(\FILEINFO_MIME);
if ($finfo) {
$file_mime_type = (string) finfo_file($finfo, $this->fichier_archive) ?: '';
$file_mime_type_raw = (string) finfo_file($finfo, $this->fichier_archive, \FILEINFO_RAW) ?: '';
finfo_close($finfo);
}
@ -150,10 +154,18 @@ abstract class AbstractArchiver implements ArchiverInterface
&& in_array($matches[1], array_keys(self::COMPRESSIONS_CONNUES))
) {
$this->mode_compression = self::COMPRESSIONS_CONNUES[$matches[1]];
} else {
$this->setErreur(2);
$file_mime_type = '';
return $file_mime_type;
}
foreach (self::COMPRESSIONS_CONNUES_RAW as $term => $mode_compression) {
if (false !== stripos($file_mime_type_raw, $term)) {
$this->mode_compression = $mode_compression;
return $file_mime_type;
}
}
$this->setErreur(2);
$file_mime_type = '';
}
return $file_mime_type;

Loading…
Cancel
Save