-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Additional Filename Sanitization (#3105)
* Update FileAdder.php Update the default filename sanitizer to handle funky whitespace characters in files - I had a case where a file was being uploaded, and it kepts throwing Flysystems `CorruptedPathDetected` exception. Not sure if copy-pasting the filename to github keeps the characters there: `Scan-9.14.2022-7.23.28.pdf` * add unit tests for PR #3031 * Fix styling Co-authored-by: Tommi Carleman <[email protected]>
- Loading branch information
1 parent
9e34cb2
commit 40cf0c6
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Spatie\MediaLibrary\Tests\MediaCollections; | ||
|
||
use Spatie\MediaLibrary\MediaCollections\FileAdder; | ||
|
||
it('sanitizes filenames correctly', function () { | ||
/** @var FileAdder $adder */ | ||
$adder = app(FileAdder::class); | ||
|
||
expect($adder->defaultSanitizer('valid-filename.jpg')) | ||
->toEqual('valid-filename.jpg'); | ||
|
||
expect($adder->defaultSanitizer('test one.pdf')) | ||
->toEqual('test-one.pdf'); | ||
|
||
expect($adder->defaultSanitizer('test#one.pdf')) | ||
->toEqual('test-one.pdf'); | ||
|
||
expect($adder->defaultSanitizer('some/test/file.pdf')) | ||
->toEqual('some-test-file.pdf'); | ||
|
||
expect($adder->defaultSanitizer('Scan-9.14.2022-7.23.28.pdf')) | ||
->toEqual('Scan-9.14.2022-7.23.28.pdf'); | ||
}); |