Skip to content

Commit

Permalink
make sure urls with leading spaces are not accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 11, 2024
1 parent bc075ca commit fae8396
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.3, 8.2]
php: [8.4, 8.3, 8.2]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"ext-fileinfo": "*"
},
"require-dev": {
"pestphp/pest": "^1.20",
"pestphp/pest": "^3.0",
"spatie/image": "^3.6",
"spatie/pdf-to-text": "^1.52",
"spatie/phpunit-snapshot-assertions": "^4.2.3"
"spatie/phpunit-snapshot-assertions": "^4.2.3|^5.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 2 additions & 0 deletions src/Browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ public function waitForSelector(string $selector, array $options = []): static

public function setUrl(string $url): static
{
$url = trim($url);

if (str_starts_with(strtolower($url), 'file://') || str_starts_with(strtolower($url), 'file:/')) {
throw FileUrlNotAllowed::make();
}
Expand Down
4 changes: 4 additions & 0 deletions tests/BrowsershotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
Browsershot::url('file://test');
})->throws(FileUrlNotAllowed::class);

it('will not allow a file url that has leading spaces', function () {
Browsershot::url(' file://test');
})->throws(FileUrlNotAllowed::class);

it('will not allow html to contain file://', function () {
Browsershot::html('<h1><img src="file://" /></h1>');
})->throws(HtmlIsNotAllowedToContainFile::class);
Expand Down

0 comments on commit fae8396

Please sign in to comment.