Merge pull request #821 from acelaya-forks/feature/slug-regex

Feature/slug regex
This commit is contained in:
Alejandro Celaya 2020-08-09 10:55:32 +02:00 committed by GitHub
commit e0760c371a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -52,7 +52,7 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
} }
$meta = $this->geoLiteDbReader->metadata(); $meta = $this->geoLiteDbReader->metadata();
if ($this->buildIsTooOld($meta->__get('buildEpoch'))) { if ($this->buildIsTooOld($meta->buildEpoch)) {
$this->downloadNewDb(true, $mustBeUpdated, $handleProgress); $this->downloadNewDb(true, $mustBeUpdated, $handleProgress);
} }
} }

View File

@ -17,6 +17,7 @@ const MIN_SHORT_CODES_LENGTH = 4;
const DEFAULT_REDIRECT_STATUS_CODE = StatusCodeInterface::STATUS_FOUND; const DEFAULT_REDIRECT_STATUS_CODE = StatusCodeInterface::STATUS_FOUND;
const DEFAULT_REDIRECT_CACHE_LIFETIME = 30; const DEFAULT_REDIRECT_CACHE_LIFETIME = 30;
const LOCAL_LOCK_FACTORY = 'Shlinkio\Shlink\LocalLockFactory'; const LOCAL_LOCK_FACTORY = 'Shlinkio\Shlink\LocalLockFactory';
const CUSTOM_SLUGS_REGEXP = '/[^A-Za-z0-9._~]+/';
function generateRandomShortCode(int $length): string function generateRandomShortCode(int $length): string
{ {

View File

@ -12,6 +12,7 @@ use Laminas\Validator;
use Shlinkio\Shlink\Common\Validation; use Shlinkio\Shlink\Common\Validation;
use Shlinkio\Shlink\Core\Util\CocurSymfonySluggerBridge; use Shlinkio\Shlink\Core\Util\CocurSymfonySluggerBridge;
use const Shlinkio\Shlink\Core\CUSTOM_SLUGS_REGEXP;
use const Shlinkio\Shlink\Core\MIN_SHORT_CODES_LENGTH; use const Shlinkio\Shlink\Core\MIN_SHORT_CODES_LENGTH;
class ShortUrlMetaInputFilter extends InputFilter class ShortUrlMetaInputFilter extends InputFilter
@ -49,8 +50,8 @@ class ShortUrlMetaInputFilter 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 Validation\SluggerFilter(new CocurSymfonySluggerBridge(new Slugify([ $customSlug->getFilterChain()->attach(new Validation\SluggerFilter(new CocurSymfonySluggerBridge(new Slugify([
'regexp' => '/[^A-Za-z0-9._~]+/', 'regexp' => CUSTOM_SLUGS_REGEXP,
'lowercase' => false, 'lowercase' => false, // We want to keep it case sensitive
])))); ]))));
$customSlug->getValidatorChain()->attach(new Validator\NotEmpty([ $customSlug->getValidatorChain()->attach(new Validator\NotEmpty([
Validator\NotEmpty::STRING, Validator\NotEmpty::STRING,