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

View file

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

View file

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

View file

@ -547,7 +547,7 @@ class ImageService
// Check the image file exists
&& $disk->exists($imagePath)
// 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-snappy": "^1.0",
"doctrine/dbal": "^3.5",
"filp/whoops": "^2.14",
"guzzlehttp/guzzle": "^7.4",
"intervention/image": "^2.7",
"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",
"This file is @generated automatically"
],
"content-hash": "58fa6b9181b7c117b88fdd2f1ae379b4",
"content-hash": "7049e76ef5eed4fe73d86bb4ecb0db6a",
"packages": [
{
"name": "aws/aws-crt-php",
@ -58,16 +58,16 @@
},
{
"name": "aws/aws-sdk-php",
"version": "3.258.3",
"version": "3.258.4",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "57cbc06827148d0d4d3f5dbe4b948daa20f82d70"
"reference": "c20d674f502ed96ed0de63e9da087eb5f0e95590"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/57cbc06827148d0d4d3f5dbe4b948daa20f82d70",
"reference": "57cbc06827148d0d4d3f5dbe4b948daa20f82d70",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/c20d674f502ed96ed0de63e9da087eb5f0e95590",
"reference": "c20d674f502ed96ed0de63e9da087eb5f0e95590",
"shasum": ""
},
"require": {
@ -146,9 +146,9 @@
"support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"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",
@ -361,25 +361,26 @@
},
{
"name": "brick/math",
"version": "0.11.0",
"version": "0.10.2",
"source": {
"type": "git",
"url": "https://github.com/brick/math.git",
"reference": "0ad82ce168c82ba30d1c01ec86116ab52f589478"
"reference": "459f2781e1a08d52ee56b0b1444086e038561e3f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/brick/math/zipball/0ad82ce168c82ba30d1c01ec86116ab52f589478",
"reference": "0ad82ce168c82ba30d1c01ec86116ab52f589478",
"url": "https://api.github.com/repos/brick/math/zipball/459f2781e1a08d52ee56b0b1444086e038561e3f",
"reference": "459f2781e1a08d52ee56b0b1444086e038561e3f",
"shasum": ""
},
"require": {
"php": "^8.0"
"ext-json": "*",
"php": "^7.4 || ^8.0"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.2",
"phpunit/phpunit": "^9.0",
"vimeo/psalm": "5.0.0"
"vimeo/psalm": "4.25.0"
},
"type": "library",
"autoload": {
@ -404,7 +405,7 @@
],
"support": {
"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": [
{
@ -412,7 +413,7 @@
"type": "github"
}
],
"time": "2023-01-15T23:15:59+00:00"
"time": "2022-08-10T22:54:19+00:00"
},
{
"name": "dasprid/enum",
@ -1234,77 +1235,6 @@
],
"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",
"version": "v1.2.0",
@ -4768,20 +4698,20 @@
},
{
"name": "ramsey/uuid",
"version": "4.x-dev",
"version": "4.7.3",
"source": {
"type": "git",
"url": "https://github.com/ramsey/uuid.git",
"reference": "25c4faac19549ebfcd3a6a73732dddeb188eaf5a"
"reference": "433b2014e3979047db08a17a205f410ba3869cf2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ramsey/uuid/zipball/25c4faac19549ebfcd3a6a73732dddeb188eaf5a",
"reference": "25c4faac19549ebfcd3a6a73732dddeb188eaf5a",
"url": "https://api.github.com/repos/ramsey/uuid/zipball/433b2014e3979047db08a17a205f410ba3869cf2",
"reference": "433b2014e3979047db08a17a205f410ba3869cf2",
"shasum": ""
},
"require": {
"brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11",
"brick/math": "^0.8.8 || ^0.9 || ^0.10",
"ext-json": "*",
"php": "^8.0",
"ramsey/collection": "^1.2 || ^2.0"
@ -4818,7 +4748,6 @@
"paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
"ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type."
},
"default-branch": true,
"type": "library",
"extra": {
"captainhook": {
@ -4845,7 +4774,7 @@
],
"support": {
"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": [
{
@ -4857,7 +4786,7 @@
"type": "tidelift"
}
],
"time": "2023-01-28T17:00:47+00:00"
"time": "2023-01-12T18:13:24+00:00"
},
{
"name": "robrichards/xmlseclibs",
@ -8013,6 +7942,77 @@
},
"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",
"version": "v2.0.1",
@ -10325,7 +10325,7 @@
}
],
"aliases": [],
"minimum-stability": "dev",
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": true,
"prefer-lowest": false,

View file

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

View file

@ -12,7 +12,7 @@ class LanguageTest extends TestCase
protected function setUp(): void
{
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()
@ -58,7 +58,7 @@ class LanguageTest extends TestCase
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 ($files as $file) {
$loadError = false;

View file

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