BookStack/app/App/Providers/ValidationRuleServiceProvider.php

31 lines
951 B
PHP
Raw Normal View History

<?php
2023-05-17 18:56:55 +02:00
namespace BookStack\App\Providers;
use BookStack\Uploads\ImageService;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
class ValidationRuleServiceProvider 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());
2021-11-01 14:26:02 +01:00
return ImageService::isExtensionSupported($extension);
});
Validator::extend('safe_url', function ($attribute, $value, $parameters, $validator) {
$cleanLinkName = strtolower(trim($value));
$isJs = str_starts_with($cleanLinkName, 'javascript:');
$isData = str_starts_with($cleanLinkName, 'data:');
2021-06-26 17:23:15 +02:00
return !$isJs && !$isData;
});
}
}