Fixed issues found from tests

This commit is contained in:
Dan Brown 2023-02-06 20:41:33 +00:00
parent 9ca088a4e2
commit 5e8ec56196
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
9 changed files with 112 additions and 118 deletions

View File

@ -2,25 +2,18 @@
namespace BookStack\Exceptions; namespace BookStack\Exceptions;
use Whoops\Handler\Handler; use Illuminate\Contracts\Foundation\ExceptionRenderer;
class WhoopsBookStackPrettyHandler extends Handler class BookStackExceptionHandlerPage implements ExceptionRenderer
{ {
/** public function render($throwable)
* @return int|null A handler may return nothing, or a Handler::HANDLE_* constant
*/
public function handle()
{ {
$exception = $this->getException(); return view('errors.debug', [
'error' => $throwable->getMessage(),
echo view('errors.debug', [ 'errorClass' => get_class($throwable),
'error' => $exception->getMessage(), 'trace' => $throwable->getTraceAsString(),
'errorClass' => get_class($exception),
'trace' => $exception->getTraceAsString(),
'environment' => $this->getEnvironment(), 'environment' => $this->getEnvironment(),
])->render(); ])->render();
return Handler::QUIT;
} }
protected function safeReturn(callable $callback, $default = null) protected function safeReturn(callable $callback, $default = null)

View File

@ -98,6 +98,7 @@ class Handler extends ExceptionHandler
]; ];
if ($e instanceof ValidationException) { if ($e instanceof ValidationException) {
$responseData['error']['message'] = 'The given data was invalid.';
$responseData['error']['validation'] = $e->errors(); $responseData['error']['validation'] = $e->errors();
$code = $e->status; $code = $e->status;
} }

View File

@ -8,16 +8,16 @@ use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf; use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page; use BookStack\Entities\Models\Page;
use BookStack\Exceptions\WhoopsBookStackPrettyHandler; use BookStack\Exceptions\BookStackExceptionHandlerPage;
use BookStack\Settings\SettingService; use BookStack\Settings\SettingService;
use BookStack\Util\CspService; use BookStack\Util\CspService;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Contracts\Foundation\ExceptionRenderer;
use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Psr\Http\Client\ClientInterface as HttpClientInterface; use Psr\Http\Client\ClientInterface as HttpClientInterface;
use Whoops\Handler\HandlerInterface;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
@ -26,7 +26,7 @@ class AppServiceProvider extends ServiceProvider
* @var string[] * @var string[]
*/ */
public $bindings = [ public $bindings = [
HandlerInterface::class => WhoopsBookStackPrettyHandler::class, ExceptionRenderer::class => BookStackExceptionHandlerPage::class,
]; ];
/** /**

View File

@ -547,7 +547,7 @@ class ImageService
// Check the image file exists // Check the image file exists
&& $disk->exists($imagePath) && $disk->exists($imagePath)
// Check the file is likely an image file // Check the file is likely an image file
&& strpos($disk->getMimetype($imagePath), 'image/') === 0; && strpos($disk->mimeType($imagePath), 'image/') === 0;
} }
/** /**

View File

@ -20,7 +20,6 @@
"barryvdh/laravel-dompdf": "^2.0", "barryvdh/laravel-dompdf": "^2.0",
"barryvdh/laravel-snappy": "^1.0", "barryvdh/laravel-snappy": "^1.0",
"doctrine/dbal": "^3.5", "doctrine/dbal": "^3.5",
"filp/whoops": "^2.14",
"guzzlehttp/guzzle": "^7.4", "guzzlehttp/guzzle": "^7.4",
"intervention/image": "^2.7", "intervention/image": "^2.7",
"laravel/framework": "^9.0", "laravel/framework": "^9.0",

190
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "58fa6b9181b7c117b88fdd2f1ae379b4", "content-hash": "7049e76ef5eed4fe73d86bb4ecb0db6a",
"packages": [ "packages": [
{ {
"name": "aws/aws-crt-php", "name": "aws/aws-crt-php",
@ -58,16 +58,16 @@
}, },
{ {
"name": "aws/aws-sdk-php", "name": "aws/aws-sdk-php",
"version": "3.258.3", "version": "3.258.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/aws/aws-sdk-php.git", "url": "https://github.com/aws/aws-sdk-php.git",
"reference": "57cbc06827148d0d4d3f5dbe4b948daa20f82d70" "reference": "c20d674f502ed96ed0de63e9da087eb5f0e95590"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/57cbc06827148d0d4d3f5dbe4b948daa20f82d70", "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/c20d674f502ed96ed0de63e9da087eb5f0e95590",
"reference": "57cbc06827148d0d4d3f5dbe4b948daa20f82d70", "reference": "c20d674f502ed96ed0de63e9da087eb5f0e95590",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -146,9 +146,9 @@
"support": { "support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues", "issues": "https://github.com/aws/aws-sdk-php/issues",
"source": "https://github.com/aws/aws-sdk-php/tree/3.258.3" "source": "https://github.com/aws/aws-sdk-php/tree/3.258.4"
}, },
"time": "2023-02-03T19:25:20+00:00" "time": "2023-02-06T19:28:40+00:00"
}, },
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
@ -361,25 +361,26 @@
}, },
{ {
"name": "brick/math", "name": "brick/math",
"version": "0.11.0", "version": "0.10.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/brick/math.git", "url": "https://github.com/brick/math.git",
"reference": "0ad82ce168c82ba30d1c01ec86116ab52f589478" "reference": "459f2781e1a08d52ee56b0b1444086e038561e3f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/brick/math/zipball/0ad82ce168c82ba30d1c01ec86116ab52f589478", "url": "https://api.github.com/repos/brick/math/zipball/459f2781e1a08d52ee56b0b1444086e038561e3f",
"reference": "0ad82ce168c82ba30d1c01ec86116ab52f589478", "reference": "459f2781e1a08d52ee56b0b1444086e038561e3f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^8.0" "ext-json": "*",
"php": "^7.4 || ^8.0"
}, },
"require-dev": { "require-dev": {
"php-coveralls/php-coveralls": "^2.2", "php-coveralls/php-coveralls": "^2.2",
"phpunit/phpunit": "^9.0", "phpunit/phpunit": "^9.0",
"vimeo/psalm": "5.0.0" "vimeo/psalm": "4.25.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -404,7 +405,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/brick/math/issues", "issues": "https://github.com/brick/math/issues",
"source": "https://github.com/brick/math/tree/0.11.0" "source": "https://github.com/brick/math/tree/0.10.2"
}, },
"funding": [ "funding": [
{ {
@ -412,7 +413,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-01-15T23:15:59+00:00" "time": "2022-08-10T22:54:19+00:00"
}, },
{ {
"name": "dasprid/enum", "name": "dasprid/enum",
@ -1234,77 +1235,6 @@
], ],
"time": "2023-01-02T17:26:14+00:00" "time": "2023-01-02T17:26:14+00:00"
}, },
{
"name": "filp/whoops",
"version": "2.14.6",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
"reference": "f7948baaa0330277c729714910336383286305da"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/filp/whoops/zipball/f7948baaa0330277c729714910336383286305da",
"reference": "f7948baaa0330277c729714910336383286305da",
"shasum": ""
},
"require": {
"php": "^5.5.9 || ^7.0 || ^8.0",
"psr/log": "^1.0.1 || ^2.0 || ^3.0"
},
"require-dev": {
"mockery/mockery": "^0.9 || ^1.0",
"phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.3",
"symfony/var-dumper": "^2.6 || ^3.0 || ^4.0 || ^5.0"
},
"suggest": {
"symfony/var-dumper": "Pretty print complex values better with var-dumper available",
"whoops/soap": "Formats errors as SOAP responses"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
}
},
"autoload": {
"psr-4": {
"Whoops\\": "src/Whoops/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Filipe Dobreira",
"homepage": "https://github.com/filp",
"role": "Developer"
}
],
"description": "php error handling for cool kids",
"homepage": "https://filp.github.io/whoops/",
"keywords": [
"error",
"exception",
"handling",
"library",
"throwable",
"whoops"
],
"support": {
"issues": "https://github.com/filp/whoops/issues",
"source": "https://github.com/filp/whoops/tree/2.14.6"
},
"funding": [
{
"url": "https://github.com/denis-sokolov",
"type": "github"
}
],
"time": "2022-11-02T16:23:29+00:00"
},
{ {
"name": "fruitcake/php-cors", "name": "fruitcake/php-cors",
"version": "v1.2.0", "version": "v1.2.0",
@ -4768,20 +4698,20 @@
}, },
{ {
"name": "ramsey/uuid", "name": "ramsey/uuid",
"version": "4.x-dev", "version": "4.7.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/ramsey/uuid.git", "url": "https://github.com/ramsey/uuid.git",
"reference": "25c4faac19549ebfcd3a6a73732dddeb188eaf5a" "reference": "433b2014e3979047db08a17a205f410ba3869cf2"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/ramsey/uuid/zipball/25c4faac19549ebfcd3a6a73732dddeb188eaf5a", "url": "https://api.github.com/repos/ramsey/uuid/zipball/433b2014e3979047db08a17a205f410ba3869cf2",
"reference": "25c4faac19549ebfcd3a6a73732dddeb188eaf5a", "reference": "433b2014e3979047db08a17a205f410ba3869cf2",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11", "brick/math": "^0.8.8 || ^0.9 || ^0.10",
"ext-json": "*", "ext-json": "*",
"php": "^8.0", "php": "^8.0",
"ramsey/collection": "^1.2 || ^2.0" "ramsey/collection": "^1.2 || ^2.0"
@ -4818,7 +4748,6 @@
"paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter", "paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
"ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type." "ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type."
}, },
"default-branch": true,
"type": "library", "type": "library",
"extra": { "extra": {
"captainhook": { "captainhook": {
@ -4845,7 +4774,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/ramsey/uuid/issues", "issues": "https://github.com/ramsey/uuid/issues",
"source": "https://github.com/ramsey/uuid/tree/4.x" "source": "https://github.com/ramsey/uuid/tree/4.7.3"
}, },
"funding": [ "funding": [
{ {
@ -4857,7 +4786,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-01-28T17:00:47+00:00" "time": "2023-01-12T18:13:24+00:00"
}, },
{ {
"name": "robrichards/xmlseclibs", "name": "robrichards/xmlseclibs",
@ -8013,6 +7942,77 @@
}, },
"time": "2022-12-13T13:54:32+00:00" "time": "2022-12-13T13:54:32+00:00"
}, },
{
"name": "filp/whoops",
"version": "2.14.6",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
"reference": "f7948baaa0330277c729714910336383286305da"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/filp/whoops/zipball/f7948baaa0330277c729714910336383286305da",
"reference": "f7948baaa0330277c729714910336383286305da",
"shasum": ""
},
"require": {
"php": "^5.5.9 || ^7.0 || ^8.0",
"psr/log": "^1.0.1 || ^2.0 || ^3.0"
},
"require-dev": {
"mockery/mockery": "^0.9 || ^1.0",
"phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.3",
"symfony/var-dumper": "^2.6 || ^3.0 || ^4.0 || ^5.0"
},
"suggest": {
"symfony/var-dumper": "Pretty print complex values better with var-dumper available",
"whoops/soap": "Formats errors as SOAP responses"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
}
},
"autoload": {
"psr-4": {
"Whoops\\": "src/Whoops/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Filipe Dobreira",
"homepage": "https://github.com/filp",
"role": "Developer"
}
],
"description": "php error handling for cool kids",
"homepage": "https://filp.github.io/whoops/",
"keywords": [
"error",
"exception",
"handling",
"library",
"throwable",
"whoops"
],
"support": {
"issues": "https://github.com/filp/whoops/issues",
"source": "https://github.com/filp/whoops/tree/2.14.6"
},
"funding": [
{
"url": "https://github.com/denis-sokolov",
"type": "github"
}
],
"time": "2022-11-02T16:23:29+00:00"
},
{ {
"name": "hamcrest/hamcrest-php", "name": "hamcrest/hamcrest-php",
"version": "v2.0.1", "version": "v2.0.1",
@ -10325,7 +10325,7 @@
} }
], ],
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": [],
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,

View File

@ -247,7 +247,7 @@ class BookTest extends TestCase
'name' => 'информация', 'name' => 'информация',
]); ]);
$this->assertEquals('informaciya', $book->slug); $this->assertEquals('informaciia', $book->slug);
$book = $this->entities->newBook([ $book = $this->entities->newBook([
'name' => '¿Qué?', 'name' => '¿Qué?',

View File

@ -12,7 +12,7 @@ class LanguageTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->langs = array_diff(scandir(resource_path('lang')), ['..', '.']); $this->langs = array_diff(scandir(lang_path('')), ['..', '.']);
} }
public function test_locales_config_key_set_properly() public function test_locales_config_key_set_properly()
@ -58,7 +58,7 @@ class LanguageTest extends TestCase
public function test_all_lang_files_loadable() public function test_all_lang_files_loadable()
{ {
$files = array_diff(scandir(resource_path('lang/en')), ['..', '.']); $files = array_diff(scandir(lang_path('en')), ['..', '.']);
foreach ($this->langs as $lang) { foreach ($this->langs as $lang) {
foreach ($files as $file) { foreach ($files as $file) {
$loadError = false; $loadError = false;

View File

@ -19,6 +19,7 @@ use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use League\CommonMark\ConfigurableEnvironmentInterface; use League\CommonMark\ConfigurableEnvironmentInterface;
use League\CommonMark\Environment\Environment;
class ThemeTest extends TestCase class ThemeTest extends TestCase
{ {
@ -57,7 +58,7 @@ class ThemeTest extends TestCase
{ {
$callbackCalled = false; $callbackCalled = false;
$callback = function ($environment) use (&$callbackCalled) { $callback = function ($environment) use (&$callbackCalled) {
$this->assertInstanceOf(ConfigurableEnvironmentInterface::class, $environment); $this->assertInstanceOf(Environment::class, $environment);
$callbackCalled = true; $callbackCalled = true;
return $environment; return $environment;