mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Rename loosely mode to loose mode
This commit is contained in:
parent
c140db16d1
commit
d847c7648e
21
CHANGELOG.md
21
CHANGELOG.md
@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
|
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
* *Nothing*
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
* [#1685](https://github.com/shlinkio/shlink/issues/1685) Changed `loosely` mode to `loose`, as it was a typo. The old one keeps working and maps to the new one, but it's considered deprecated.
|
||||||
|
|
||||||
|
### Deprecated
|
||||||
|
* *Nothing*
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
* *Nothing*
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
* *Nothing*
|
||||||
|
|
||||||
|
|
||||||
## [3.5.0] - 2023-01-28
|
## [3.5.0] - 2023-01-28
|
||||||
### Added
|
### Added
|
||||||
* [#1557](https://github.com/shlinkio/shlink/issues/1557) Added support to dynamically redirect to different long URLs based on the visitor's device type.
|
* [#1557](https://github.com/shlinkio/shlink/issues/1557) Added support to dynamically redirect to different long URLs based on the visitor's device type.
|
||||||
@ -25,9 +42,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
|
|||||||
* [#1662](https://github.com/shlinkio/shlink/issues/1662) Added support to provide openswoole-specific config options via env vars prefixed with `OPENSWOOLE_`.
|
* [#1662](https://github.com/shlinkio/shlink/issues/1662) Added support to provide openswoole-specific config options via env vars prefixed with `OPENSWOOLE_`.
|
||||||
* [#1389](https://github.com/shlinkio/shlink/issues/1389) and [#706](https://github.com/shlinkio/shlink/issues/706) Added support for case-insensitive short URLs.
|
* [#1389](https://github.com/shlinkio/shlink/issues/1389) and [#706](https://github.com/shlinkio/shlink/issues/706) Added support for case-insensitive short URLs.
|
||||||
|
|
||||||
In order to achieve this, a new env var/config option has been implemented (`SHORT_URL_MODE`), which allows either `strict` or `loosely`.
|
In order to achieve this, a new env var/config option has been implemented (`SHORT_URL_MODE`), which allows either `strict` or ~~`loosely`~~ `loose`.
|
||||||
|
|
||||||
Default value is `strict`, but if `loosely` is provided, then short URLs will be matched in a case-insensitive way, and new short URLs will be generated with short-codes in lowercase only.
|
Default value is `strict`, but if `loose` is provided, then short URLs will be matched in a case-insensitive way, and new short URLs will be generated with short-codes in lowercase only.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* *Nothing*
|
* *Nothing*
|
||||||
|
@ -14,7 +14,7 @@ return (static function (): array {
|
|||||||
MIN_SHORT_CODES_LENGTH,
|
MIN_SHORT_CODES_LENGTH,
|
||||||
);
|
);
|
||||||
$modeFromEnv = EnvVars::SHORT_URL_MODE->loadFromEnv(ShortUrlMode::STRICT->value);
|
$modeFromEnv = EnvVars::SHORT_URL_MODE->loadFromEnv(ShortUrlMode::STRICT->value);
|
||||||
$mode = ShortUrlMode::tryFrom($modeFromEnv) ?? ShortUrlMode::STRICT;
|
$mode = ShortUrlMode::tryDeprecated($modeFromEnv) ?? ShortUrlMode::STRICT;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ final class UrlShortenerOptions
|
|||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isLooselyMode(): bool
|
public function isLooseMode(): bool
|
||||||
{
|
{
|
||||||
return $this->mode === ShortUrlMode::LOOSELY;
|
return $this->mode === ShortUrlMode::LOOSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,11 @@ namespace Shlinkio\Shlink\Core\ShortUrl\Model;
|
|||||||
enum ShortUrlMode: string
|
enum ShortUrlMode: string
|
||||||
{
|
{
|
||||||
case STRICT = 'strict';
|
case STRICT = 'strict';
|
||||||
case LOOSELY = 'loosely';
|
case LOOSE = 'loose';
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
|
public static function tryDeprecated(string $mode): ?self
|
||||||
|
{
|
||||||
|
return $mode === 'loosely' ? self::LOOSE : self::tryFrom($mode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class CustomSlugFilter implements FilterInterface
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $this->options->isLooselyMode() ? strtolower($value) : $value;
|
$value = $this->options->isLooseMode() ? strtolower($value) : $value;
|
||||||
return (match ($this->options->multiSegmentSlugsEnabled) {
|
return (match ($this->options->multiSegmentSlugsEnabled) {
|
||||||
true => trim(str_replace(' ', '-', $value), '/'),
|
true => trim(str_replace(' ', '-', $value), '/'),
|
||||||
false => str_replace([' ', '/'], '-', $value),
|
false => str_replace([' ', '/'], '-', $value),
|
||||||
|
@ -55,13 +55,13 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
|||||||
));
|
));
|
||||||
self::assertSame($regularOne, $this->repo->findOneWithDomainFallback(
|
self::assertSame($regularOne, $this->repo->findOneWithDomainFallback(
|
||||||
ShortUrlIdentifier::fromShortCodeAndDomain('foo'),
|
ShortUrlIdentifier::fromShortCodeAndDomain('foo'),
|
||||||
ShortUrlMode::LOOSELY,
|
ShortUrlMode::LOOSE,
|
||||||
));
|
));
|
||||||
self::assertSame($regularOne, $this->repo->findOneWithDomainFallback(
|
self::assertSame($regularOne, $this->repo->findOneWithDomainFallback(
|
||||||
ShortUrlIdentifier::fromShortCodeAndDomain('fOo'),
|
ShortUrlIdentifier::fromShortCodeAndDomain('fOo'),
|
||||||
ShortUrlMode::LOOSELY,
|
ShortUrlMode::LOOSE,
|
||||||
));
|
));
|
||||||
// TODO MS is doing loosely checks always, making this fail.
|
// TODO MS is doing loose checks always, making this fail.
|
||||||
if (! $this->getEntityManager()->getConnection()->getDatabasePlatform() instanceof SQLServerPlatform) {
|
if (! $this->getEntityManager()->getConnection()->getDatabasePlatform() instanceof SQLServerPlatform) {
|
||||||
self::assertNull($this->repo->findOneWithDomainFallback(
|
self::assertNull($this->repo->findOneWithDomainFallback(
|
||||||
ShortUrlIdentifier::fromShortCodeAndDomain('foo'),
|
ShortUrlIdentifier::fromShortCodeAndDomain('foo'),
|
||||||
|
@ -139,7 +139,7 @@ class ShortUrlTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function generatesLowercaseOnlyShortCodesInLooselyMode(): void
|
public function generatesLowercaseOnlyShortCodesInLooseMode(): void
|
||||||
{
|
{
|
||||||
$range = range(1, 1000); // Use a "big" number to reduce false negatives
|
$range = range(1, 1000); // Use a "big" number to reduce false negatives
|
||||||
$allFor = static fn (ShortUrlMode $mode): bool => every($range, static function () use ($mode): bool {
|
$allFor = static fn (ShortUrlMode $mode): bool => every($range, static function () use ($mode): bool {
|
||||||
@ -152,7 +152,7 @@ class ShortUrlTest extends TestCase
|
|||||||
return $shortCode === strtolower($shortCode);
|
return $shortCode === strtolower($shortCode);
|
||||||
});
|
});
|
||||||
|
|
||||||
self::assertTrue($allFor(ShortUrlMode::LOOSELY));
|
self::assertTrue($allFor(ShortUrlMode::LOOSE));
|
||||||
self::assertFalse($allFor(ShortUrlMode::STRICT));
|
self::assertFalse($allFor(ShortUrlMode::STRICT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,20 +140,20 @@ class ShortUrlCreationTest extends TestCase
|
|||||||
{
|
{
|
||||||
yield ['🔥', '🔥'];
|
yield ['🔥', '🔥'];
|
||||||
yield ['🦣 🍅', '🦣-🍅'];
|
yield ['🦣 🍅', '🦣-🍅'];
|
||||||
yield ['🦣 🍅', '🦣-🍅', false, ShortUrlMode::LOOSELY];
|
yield ['🦣 🍅', '🦣-🍅', false, ShortUrlMode::LOOSE];
|
||||||
yield ['foobar', 'foobar'];
|
yield ['foobar', 'foobar'];
|
||||||
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', false, ShortUrlMode::LOOSELY];
|
yield ['foo BAR-baz', 'foo-bar-baz', false, ShortUrlMode::LOOSE];
|
||||||
yield ['foo/bar/baz', 'foo/bar/baz', true];
|
yield ['foo/bar/baz', 'foo/bar/baz', true];
|
||||||
yield ['/foo/bar/baz', 'foo/bar/baz', true];
|
yield ['/foo/bar/baz', 'foo/bar/baz', true];
|
||||||
yield ['/foo/baR/baZ', 'foo/bar/baz', true, ShortUrlMode::LOOSELY];
|
yield ['/foo/baR/baZ', 'foo/bar/baz', true, ShortUrlMode::LOOSE];
|
||||||
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 ['UPPER_lower', 'upper_lower', false, ShortUrlMode::LOOSELY];
|
yield ['UPPER_lower', 'upper_lower', false, ShortUrlMode::LOOSE];
|
||||||
yield ['more~url_special.chars', 'more~url_special.chars'];
|
yield ['more~url_special.chars', 'more~url_special.chars'];
|
||||||
yield ['구글', '구글'];
|
yield ['구글', '구글'];
|
||||||
yield ['グーグル', 'グーグル'];
|
yield ['グーグル', 'グーグル'];
|
||||||
|
Loading…
Reference in New Issue
Block a user