Skip to content

Commit

Permalink
Fix for #40 - use original file name of archive to check content
Browse files Browse the repository at this point in the history
  • Loading branch information
wapmorgan committed Jan 17, 2023
1 parent 4a3a29d commit 6a28da2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/Formats.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use wapmorgan\UnifiedArchive\Drivers\TarByPear;
use wapmorgan\UnifiedArchive\Drivers\TarByPhar;
use wapmorgan\UnifiedArchive\Drivers\Zip;
use wapmorgan\UnifiedArchive\Formats\Tar;

class Formats
{
Expand Down Expand Up @@ -122,13 +121,13 @@ class Formats
/**
* Detect archive type by its filename or content
*
* @param string $fileName Archive filename
* @param string $originalFileName Archive filename
* @param bool $contentCheck Whether archive type can be detected by content
* @return string|bool One of UnifiedArchive type constants OR false if type is not detected
*/
public static function detectArchiveFormat($fileName, $contentCheck = true)
public static function detectArchiveFormat($originalFileName, $contentCheck = true)
{
$fileName = strtolower($fileName);
$fileName = strtolower($originalFileName);

// by file name
$ld_offset = strrpos($fileName, '.');
Expand All @@ -148,7 +147,7 @@ public static function detectArchiveFormat($fileName, $contentCheck = true)

// by file content
if ($contentCheck && function_exists('mime_content_type')) {
$mime_type = mime_content_type($fileName);
$mime_type = mime_content_type($originalFileName);
if (isset(static::$mimeTypes[$mime_type])) {
return static::$mimeTypes[$mime_type];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ test:
docker run --rm --interactive --tty --volume $(PWD):/app -w /app -e XDEBUG_MODE=coverage --add-host=host.docker.internal:host-gateway php:ua ./vendor/bin/phpunit --coverage-text

run:
docker run --rm --interactive --tty --volume $(PWD):/app -w /app --add-host=host.docker.internal:host-gateway php:ua bash
docker run --rm --interactive --tty --volume $(PWD):/app -w /app --add-host=host.docker.internal:host-gateway php:ua bash

0 comments on commit 6a28da2

Please sign in to comment.