Skip to content

Commit

Permalink
Check if extension
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 authored Dec 11, 2023
1 parent bcda3ee commit e4b8d8b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/MediaCollections/FileAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Stringable;
use Illuminate\Support\Traits\Macroable;
use Spatie\MediaLibrary\Conversions\ImageGenerators\Image as ImageGenerator;
use Spatie\MediaLibrary\HasMedia;
Expand Down Expand Up @@ -406,13 +407,13 @@ public function defaultSanitizer(string $fileName): string
$extension = pathinfo($fileName, PATHINFO_EXTENSION);

$fileName = str($fileName)
->basename(".{$extension}")
->when($extension, fn (Stringable $str) => $str->basename(".{$extension}"))
->matchAll('/[\p{L}\p{N}\._]+/u')
->implode('-');

return str($fileName)
->trim('.')
->append(".{$extension}")
->when($extension, fn (Stringable $str) => $str->append(".{$extension}"))
->value();
}

Expand Down

0 comments on commit e4b8d8b

Please sign in to comment.