Skip to content

Commit

Permalink
[3.4] Revert overzealous file extension renaming feature (#9399)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Jan 25, 2024
1 parent c9143b3 commit 3c4280f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
26 changes: 1 addition & 25 deletions src/Assets/AssetUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function asset(Asset $asset)

protected function uploadPath(UploadedFile $file)
{
$ext = $this->getFileExtension($file);
$ext = $file->getClientOriginalExtension();
$filename = self::getSafeFilename(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));

$directory = $this->asset->folder();
Expand All @@ -51,30 +51,6 @@ protected function disk()
return $this->asset->container()->disk();
}

private function getFileExtension(UploadedFile $file)
{
$extension = $file->getClientOriginalExtension();
$guessed = $file->guessExtension();

// Only use the guessed extension if it's different than the original.
// This allows us to maintain the casing of the original extension
// if the the "lowercase filenames" config option is disabled.
return $this->isEqualExtension($extension, $guessed) ? $extension : $guessed;
}

private function isEqualExtension($a, $b)
{
$a = strtolower($a);
$b = strtolower($b);

// In earlier versions of Symfony, the guessed extension for JPEGs was "jpeg".
// We'll consider them equal so we don't need to tweak any tests.
// They're technically equal anyway.
return $a === $b
|| ($a == 'jpeg' && $b == 'jpg')
|| ($a == 'jpg' && $b == 'jpeg');
}

public static function getSafeFilename($string)
{
$replacements = [
Expand Down
16 changes: 1 addition & 15 deletions src/Assets/FileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,7 @@ public static function container(string $container = null)

protected function uploadPath(UploadedFile $file)
{
$filename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);

return now()->timestamp.'/'.$filename.'.'.$this->extension($file);
}

private function extension(UploadedFile $file)
{
$extension = $file->getClientOriginalExtension();
$guessed = $file->guessExtension();

$isEqual = $extension === $guessed
|| ($extension === 'jpeg' && $guessed === 'jpg')
|| ($extension === 'jpg' && $guessed === 'jpeg');

return $isEqual ? $extension : $guessed;
return now()->timestamp.'/'.$file->getClientOriginalName();
}

protected function uploadPathPrefix()
Expand Down

0 comments on commit 3c4280f

Please sign in to comment.