Skip to content

Commit

Permalink
Merge pull request #5096 from DanielGordonIT/normalize-file-extensions
Browse files Browse the repository at this point in the history
Wraps file extension comparison components in strtolower()
  • Loading branch information
ssddanbrown authored Jul 14, 2024
2 parents 95c3cc5 + ca31096 commit ddec809
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Uploads/ImageRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function updateImageDetails(Image $image, $updateDetails): Image
*/
public function updateImageFile(Image $image, UploadedFile $file): void
{
if ($file->getClientOriginalExtension() !== pathinfo($image->path, PATHINFO_EXTENSION)) {
if (strtolower($file->getClientOriginalExtension()) !== strtolower(pathinfo($image->path, PATHINFO_EXTENSION))) {
throw new ImageUploadException(trans('errors.image_upload_replace_type'));
}

Expand Down
27 changes: 27 additions & 0 deletions tests/Uploads/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,33 @@ public function test_image_file_update()
$this->files->deleteAtRelativePath($relPath);
}

public function test_image_file_update_allows_case_differences()
{
$page = $this->entities->page();
$this->asEditor();

$imgDetails = $this->files->uploadGalleryImageToPage($this, $page);
$relPath = $imgDetails['path'];

$newUpload = $this->files->uploadedImage('updated-image.PNG', 'compressed.png');
$this->assertFileEquals($this->files->testFilePath('test-image.png'), public_path($relPath));

$imageId = $imgDetails['response']->id;
$image = Image::findOrFail($imageId);
$image->updated_at = now()->subMonth();
$image->save();

$this->call('PUT', "/images/{$imageId}/file", [], [], ['file' => $newUpload])
->assertOk();

$this->assertFileEquals($this->files->testFilePath('compressed.png'), public_path($relPath));

$image->refresh();
$this->assertTrue($image->updated_at->gt(now()->subMinute()));

$this->files->deleteAtRelativePath($relPath);
}

public function test_image_file_update_does_not_allow_change_in_image_extension()
{
$page = $this->entities->page();
Expand Down

0 comments on commit ddec809

Please sign in to comment.