diff --git a/src/Browsershot.php b/src/Browsershot.php index 2eedd100..b7b4d6e0 100644 --- a/src/Browsershot.php +++ b/src/Browsershot.php @@ -4,6 +4,7 @@ use Spatie\Browsershot\Exceptions\CouldNotTakeBrowsershot; use Spatie\Browsershot\Exceptions\ElementNotFound; +use Spatie\Browsershot\Exceptions\FileUrlNotAllowed; use Spatie\Browsershot\Exceptions\UnsuccessfulResponse; use Spatie\Image\Image; use Spatie\Image\Manipulations; @@ -235,6 +236,10 @@ public function waitForFunction(string $function, $polling = self::POLLING_REQUE public function setUrl(string $url) { + if (Helpers::stringStartsWith(strtolower($url), 'file://')) { + throw FileUrlNotAllowed::make(); + } + $this->url = $url; $this->html = ''; diff --git a/src/Exceptions/FileUrlNotAllowed.php b/src/Exceptions/FileUrlNotAllowed.php new file mode 100644 index 00000000..4b2bd396 --- /dev/null +++ b/src/Exceptions/FileUrlNotAllowed.php @@ -0,0 +1,13 @@ +throws(FileUrlNotAllowed::class); + it('can take a screenshot', function () { $targetPath = __DIR__.'/temp/testScreenshot.png'; diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php new file mode 100644 index 00000000..94458c68 --- /dev/null +++ b/tests/HelpersTest.php @@ -0,0 +1,12 @@ +toBe($expectedResult); +})->with([ + ['https://spatie.be', 'https://', true], + ['http://spatie.be', 'https://', false], + ['file://hey', 'file://', true], + ['https://spatie.be', 'file://', false], +]);