File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ class Browsershot
6969 protected ImageManipulations $ imageManipulations ;
7070
7171 protected array $ unsafeProtocols = [
72- 'file:, ' ,
72+ 'file: ' ,
7373 'file:/ ' ,
7474 'file:// ' ,
7575 'file: \\' ,
@@ -268,6 +268,10 @@ public function setUrl(string $url): static
268268 {
269269 $ url = trim ($ url );
270270
271+ if (filter_var ($ url , FILTER_VALIDATE_URL ) === false ){
272+ throw FileUrlNotAllowed::urlCannotBeParsed ($ url );
273+ }
274+
271275 foreach ($ this ->unsafeProtocols as $ unsupportedProtocol ) {
272276 if (str_starts_with (strtolower ($ url ), $ unsupportedProtocol )) {
273277 throw FileUrlNotAllowed::make ();
Original file line number Diff line number Diff line change @@ -10,4 +10,9 @@ public static function make(): static
1010 {
1111 return new static ('An URL is not allow to start with file:// or file:/ ' );
1212 }
13+
14+ public static function urlCannotBeParsed (string $ url ): static
15+ {
16+ return new static ("The given URL ` {$ url }` is not a valid URL " );
17+ }
1318}
Original file line number Diff line number Diff line change 5959 'File://test ' ,
6060 'file:/test ' ,
6161 'file:\test ' ,
62+ 'file: ' ,
6263 'file: \\test ' ,
6364 'view-source ' ,
6465 'View-Source ' ,
6566]);
6667
68+ it ('will not allow a malformed file url with too many slashes ' , function () {
69+ Browsershot::url ('fil
70+ e:///test ' );
71+ })->throws (FileUrlNotAllowed::class);
72+
6773it ('will not allow a file url that has leading spaces ' , function () {
6874 Browsershot::url (' file://test ' );
6975})->throws (FileUrlNotAllowed::class);
You can’t perform that action at this time.
0 commit comments