Allowed slashes on custom slugs during short URL creation

This commit is contained in:
Alejandro Celaya
2022-08-01 10:12:08 +02:00
parent e0e511f56d
commit 0a220bbc7a
2 changed files with 4 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ use Shlinkio\Shlink\Common\Validation;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use function is_string;
use function ltrim;
use function str_replace;
use function substr;
@@ -77,7 +78,7 @@ class ShortUrlInputFilter extends InputFilter
// empty, is by using the deprecated setContinueIfEmpty
$customSlug = $this->createInput(self::CUSTOM_SLUG, false)->setContinueIfEmpty(true);
$customSlug->getFilterChain()->attach(new Filter\Callback(
static fn (mixed $value) => is_string($value) ? str_replace([' ', '/'], '-', $value) : $value,
static fn (mixed $value) => is_string($value) ? ltrim(str_replace(' ', '-', $value), '/') : $value,
));
$customSlug->getValidatorChain()->attach(new Validator\NotEmpty([
Validator\NotEmpty::STRING,