Skip to content

Commit ddec809

Browse files
authored
Merge pull request #5096 from DanielGordonIT/normalize-file-extensions
Wraps file extension comparison components in strtolower()
2 parents 95c3cc5 + ca31096 commit ddec809

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

app/Uploads/ImageRepo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function updateImageDetails(Image $image, $updateDetails): Image
166166
*/
167167
public function updateImageFile(Image $image, UploadedFile $file): void
168168
{
169-
if ($file->getClientOriginalExtension() !== pathinfo($image->path, PATHINFO_EXTENSION)) {
169+
if (strtolower($file->getClientOriginalExtension()) !== strtolower(pathinfo($image->path, PATHINFO_EXTENSION))) {
170170
throw new ImageUploadException(trans('errors.image_upload_replace_type'));
171171
}
172172

tests/Uploads/ImageTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,33 @@ public function test_image_file_update()
119119
$this->files->deleteAtRelativePath($relPath);
120120
}
121121

122+
public function test_image_file_update_allows_case_differences()
123+
{
124+
$page = $this->entities->page();
125+
$this->asEditor();
126+
127+
$imgDetails = $this->files->uploadGalleryImageToPage($this, $page);
128+
$relPath = $imgDetails['path'];
129+
130+
$newUpload = $this->files->uploadedImage('updated-image.PNG', 'compressed.png');
131+
$this->assertFileEquals($this->files->testFilePath('test-image.png'), public_path($relPath));
132+
133+
$imageId = $imgDetails['response']->id;
134+
$image = Image::findOrFail($imageId);
135+
$image->updated_at = now()->subMonth();
136+
$image->save();
137+
138+
$this->call('PUT', "/images/{$imageId}/file", [], [], ['file' => $newUpload])
139+
->assertOk();
140+
141+
$this->assertFileEquals($this->files->testFilePath('compressed.png'), public_path($relPath));
142+
143+
$image->refresh();
144+
$this->assertTrue($image->updated_at->gt(now()->subMinute()));
145+
146+
$this->files->deleteAtRelativePath($relPath);
147+
}
148+
122149
public function test_image_file_update_does_not_allow_change_in_image_extension()
123150
{
124151
$page = $this->entities->page();

0 commit comments

Comments
 (0)