File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace UniSharp \LaravelFilemanager \Exceptions ;
4+
5+ class InvalidExtensionException extends \Exception
6+ {
7+ public function __construct ()
8+ {
9+ $ this ->message = 'File extension is not valid. ' ;
10+ }
11+ }
Original file line number Diff line number Diff line change 99use UniSharp \LaravelFilemanager \Exceptions \FileFailedToUploadException ;
1010use UniSharp \LaravelFilemanager \Exceptions \FileSizeExceedConfigurationMaximumException ;
1111use UniSharp \LaravelFilemanager \Exceptions \FileSizeExceedIniMaximumException ;
12+ use UniSharp \LaravelFilemanager \Exceptions \InvalidExtensionException ;
1213use UniSharp \LaravelFilemanager \Exceptions \InvalidMimeTypeException ;
1314use UniSharp \LaravelFilemanager \LfmPath ;
1415
@@ -94,6 +95,17 @@ public function mimeTypeIsValid($available_mime_types)
9495 return $ this ;
9596 }
9697
98+ public function extensionIsValid ()
99+ {
100+ $ extension = strtolower ($ this ->file ->getClientOriginalExtension ());
101+
102+ if (preg_match ('/[^a-zA-Z0-9]/ ' , $ extension ) > 0 ) {
103+ throw new InvalidExtensionException ();
104+ }
105+
106+ return $ this ;
107+ }
108+
97109 public function sizeIsLowerThanConfiguredMaximum ($ max_size_in_kb )
98110 {
99111 // size to kb unit is needed
Original file line number Diff line number Diff line change 99use UniSharp \LaravelFilemanager \Exceptions \FileFailedToUploadException ;
1010use UniSharp \LaravelFilemanager \Exceptions \FileSizeExceedConfigurationMaximumException ;
1111use UniSharp \LaravelFilemanager \Exceptions \FileSizeExceedIniMaximumException ;
12+ use UniSharp \LaravelFilemanager \Exceptions \InvalidExtensionException ;
1213use UniSharp \LaravelFilemanager \Exceptions \InvalidMimeTypeException ;
1314use UniSharp \LaravelFilemanager \LfmPath ;
1415use UniSharp \LaravelFilemanager \LfmUploadValidator ;
@@ -167,6 +168,18 @@ public function testFailsExtensionIsNotExcutableWithExtensionNotLowerCase()
167168 $ validator ->extensionIsNotExcutable (['php ' , 'html ' ]);
168169 }
169170
171+ public function testFailsExtensionIsValidWithSpecialCharacters ()
172+ {
173+ $ uploaded_file = m::mock (UploadedFile::class);
174+ $ uploaded_file ->shouldReceive ('getClientOriginalExtension ' )->andReturn ('html@ ' );
175+
176+ $ validator = new LfmUploadValidator ($ uploaded_file );
177+
178+ $ this ->expectException (InvalidExtensionException::class);
179+
180+ $ validator ->extensionIsValid ();
181+ }
182+
170183 public function testPassesSizeIsLowerThanConfiguredMaximum ()
171184 {
172185 $ uploaded_file = m::mock (UploadedFile::class);
You can’t perform that action at this time.
0 commit comments