-
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2a8888
commit 92cf16f
Showing
5 changed files
with
48 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,13 @@ | ||
<?php | ||
|
||
namespace Spatie\Browsershot\Exceptions; | ||
|
||
use Exception; | ||
|
||
class FileUrlNotAllowed extends Exception | ||
{ | ||
public static function make() | ||
{ | ||
return new static("An URL is not allow to start with file://"); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Spatie\Browsershot; | ||
|
||
class Helpers | ||
{ | ||
public static function stringStartsWith($haystack, $needle): bool | ||
{ | ||
$length = strlen($needle); | ||
|
||
return substr( $haystack, 0, $length ) === $needle; | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
use Spatie\Browsershot\Helpers; | ||
|
||
it('can determine if a string starts with a substring', function(string $haystack, $needle, $expectedResult) { | ||
expect(Helpers::stringStartsWith($haystack, $needle))->toBe($expectedResult); | ||
})->with([ | ||
['https://spatie.be', 'https://', true], | ||
['http://spatie.be', 'https://', false], | ||
['file://hey', 'file://', true], | ||
['https://spatie.be', 'file://', false], | ||
]); |