BookStack/app/Providers/CustomValidationServiceProvider.php

31 lines
943 B
PHP
Raw Normal View History

<?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());
2021-11-01 09:26:02 -04:00
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;
2021-06-26 11:23:15 -04:00
return !$isJs && !$isData;
});
}
}