mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-04 23:13:41 +08:00
c7fea8fe08
- Moved out extension check to ImageService as that seems more relevant. - Updated models to use static-style references instead of facade to align with common modern usage within the app. - Updated custom image_extension validation rule to use shared logic in image service.
30 lines
942 B
PHP
30 lines
942 B
PHP
<?php
|
|
|
|
namespace BookStack\Providers;
|
|
|
|
use BookStack\Uploads\ImageService;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class CustomValidationServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register our custom validation rules when the application boots.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
|
|
$extension = strtolower($value->getClientOriginalExtension());
|
|
return ImageService::isExtensionSupported($extension);
|
|
});
|
|
|
|
Validator::extend('safe_url', function ($attribute, $value, $parameters, $validator) {
|
|
$cleanLinkName = strtolower(trim($value));
|
|
$isJs = strpos($cleanLinkName, 'javascript:') === 0;
|
|
$isData = strpos($cleanLinkName, 'data:') === 0;
|
|
|
|
return !$isJs && !$isData;
|
|
});
|
|
}
|
|
}
|