From 41d3826c1afa2f7e2d46e8b8bc5c19002577b15b Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 10 Jan 2022 10:43:20 +0100 Subject: [PATCH] Ensured bars are replaced by dashes in custom slugs --- module/Core/src/Validation/ShortUrlInputFilter.php | 2 +- module/Core/test/Model/ShortUrlMetaTest.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/module/Core/src/Validation/ShortUrlInputFilter.php b/module/Core/src/Validation/ShortUrlInputFilter.php index 96896e94..6cd578fb 100644 --- a/module/Core/src/Validation/ShortUrlInputFilter.php +++ b/module/Core/src/Validation/ShortUrlInputFilter.php @@ -77,7 +77,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) ? str_replace([' ', '/'], '-', $value) : $value, )); $customSlug->getValidatorChain()->attach(new Validator\NotEmpty([ Validator\NotEmpty::STRING, diff --git a/module/Core/test/Model/ShortUrlMetaTest.php b/module/Core/test/Model/ShortUrlMetaTest.php index ec2d314e..1933b3b6 100644 --- a/module/Core/test/Model/ShortUrlMetaTest.php +++ b/module/Core/test/Model/ShortUrlMetaTest.php @@ -57,10 +57,6 @@ class ShortUrlMetaTest extends TestCase ShortUrlInputFilter::LONG_URL => 'foo', ShortUrlInputFilter::SHORT_CODE_LENGTH => 3, ]]; - yield [[ - ShortUrlInputFilter::LONG_URL => 'foo', - ShortUrlInputFilter::CUSTOM_SLUG => '/', - ]]; yield [[ ShortUrlInputFilter::LONG_URL => 'foo', ShortUrlInputFilter::CUSTOM_SLUG => '', @@ -107,6 +103,7 @@ class ShortUrlMetaTest extends TestCase yield ['foo bar', 'foo-bar']; yield ['foo bar baz', 'foo-bar-baz']; yield ['foo bar-baz', 'foo-bar-baz']; + yield ['foo/bar/baz', 'foo-bar-baz']; yield ['wp-admin.php', 'wp-admin.php']; yield ['UPPER_lower', 'UPPER_lower']; yield ['more~url_special.chars', 'more~url_special.chars'];