File tree 3 files changed +16
-1
lines changed
3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ class Browsershot
69
69
protected ImageManipulations $ imageManipulations ;
70
70
71
71
protected array $ unsafeProtocols = [
72
- 'file:, ' ,
72
+ 'file: ' ,
73
73
'file:/ ' ,
74
74
'file:// ' ,
75
75
'file: \\' ,
@@ -268,6 +268,10 @@ public function setUrl(string $url): static
268
268
{
269
269
$ url = trim ($ url );
270
270
271
+ if (filter_var ($ url , FILTER_VALIDATE_URL ) === false ){
272
+ throw FileUrlNotAllowed::urlCannotBeParsed ($ url );
273
+ }
274
+
271
275
foreach ($ this ->unsafeProtocols as $ unsupportedProtocol ) {
272
276
if (str_starts_with (strtolower ($ url ), $ unsupportedProtocol )) {
273
277
throw FileUrlNotAllowed::make ();
Original file line number Diff line number Diff line change @@ -10,4 +10,9 @@ public static function make(): static
10
10
{
11
11
return new static ('An URL is not allow to start with file:// or file:/ ' );
12
12
}
13
+
14
+ public static function urlCannotBeParsed (string $ url ): static
15
+ {
16
+ return new static ("The given URL ` {$ url }` is not a valid URL " );
17
+ }
13
18
}
Original file line number Diff line number Diff line change 59
59
'File://test ' ,
60
60
'file:/test ' ,
61
61
'file:\test ' ,
62
+ 'file: ' ,
62
63
'file: \\test ' ,
63
64
'view-source ' ,
64
65
'View-Source ' ,
65
66
]);
66
67
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
+
67
73
it ('will not allow a file url that has leading spaces ' , function () {
68
74
Browsershot::url (' file://test ' );
69
75
})->throws (FileUrlNotAllowed::class);
You can’t perform that action at this time.
0 commit comments