mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 23:23:42 -06:00
Ensured bars are replaced by dashes in custom slugs
This commit is contained in:
parent
f2ff6e6a70
commit
41d3826c1a
@ -77,7 +77,7 @@ class ShortUrlInputFilter extends InputFilter
|
|||||||
// empty, is by using the deprecated setContinueIfEmpty
|
// empty, is by using the deprecated setContinueIfEmpty
|
||||||
$customSlug = $this->createInput(self::CUSTOM_SLUG, false)->setContinueIfEmpty(true);
|
$customSlug = $this->createInput(self::CUSTOM_SLUG, false)->setContinueIfEmpty(true);
|
||||||
$customSlug->getFilterChain()->attach(new Filter\Callback(
|
$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([
|
$customSlug->getValidatorChain()->attach(new Validator\NotEmpty([
|
||||||
Validator\NotEmpty::STRING,
|
Validator\NotEmpty::STRING,
|
||||||
|
@ -57,10 +57,6 @@ class ShortUrlMetaTest extends TestCase
|
|||||||
ShortUrlInputFilter::LONG_URL => 'foo',
|
ShortUrlInputFilter::LONG_URL => 'foo',
|
||||||
ShortUrlInputFilter::SHORT_CODE_LENGTH => 3,
|
ShortUrlInputFilter::SHORT_CODE_LENGTH => 3,
|
||||||
]];
|
]];
|
||||||
yield [[
|
|
||||||
ShortUrlInputFilter::LONG_URL => 'foo',
|
|
||||||
ShortUrlInputFilter::CUSTOM_SLUG => '/',
|
|
||||||
]];
|
|
||||||
yield [[
|
yield [[
|
||||||
ShortUrlInputFilter::LONG_URL => 'foo',
|
ShortUrlInputFilter::LONG_URL => 'foo',
|
||||||
ShortUrlInputFilter::CUSTOM_SLUG => '',
|
ShortUrlInputFilter::CUSTOM_SLUG => '',
|
||||||
@ -107,6 +103,7 @@ class ShortUrlMetaTest extends TestCase
|
|||||||
yield ['foo bar', 'foo-bar'];
|
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 ['foo bar-baz', 'foo-bar-baz'];
|
||||||
|
yield ['foo/bar/baz', 'foo-bar-baz'];
|
||||||
yield ['wp-admin.php', 'wp-admin.php'];
|
yield ['wp-admin.php', 'wp-admin.php'];
|
||||||
yield ['UPPER_lower', 'UPPER_lower'];
|
yield ['UPPER_lower', 'UPPER_lower'];
|
||||||
yield ['more~url_special.chars', 'more~url_special.chars'];
|
yield ['more~url_special.chars', 'more~url_special.chars'];
|
||||||
|
Loading…
Reference in New Issue
Block a user