mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-26 02:40:41 -06:00
Enforced short URLs length to be 4 at least
This commit is contained in:
parent
13555366e3
commit
9372d1739a
@ -43,7 +43,7 @@ class ShortUrlMetaInputFilter extends InputFilter
|
||||
$this->add($customSlug);
|
||||
|
||||
$this->add($this->createPositiveNumberInput(self::MAX_VISITS));
|
||||
$this->add($this->createPositiveNumberInput(self::SHORT_CODE_LENGTH));
|
||||
$this->add($this->createPositiveNumberInput(self::SHORT_CODE_LENGTH, 4));
|
||||
|
||||
$this->add($this->createBooleanInput(self::FIND_IF_EXISTS, false));
|
||||
|
||||
@ -52,11 +52,11 @@ class ShortUrlMetaInputFilter extends InputFilter
|
||||
$this->add($domain);
|
||||
}
|
||||
|
||||
private function createPositiveNumberInput(string $name): Input
|
||||
private function createPositiveNumberInput(string $name, int $min = 1): Input
|
||||
{
|
||||
$input = $this->createInput($name, false);
|
||||
$input->getValidatorChain()->attach(new Validator\Digits())
|
||||
->attach(new Validator\GreaterThan(['min' => 1, 'inclusive' => true]));
|
||||
->attach(new Validator\GreaterThan(['min' => $min, 'inclusive' => true]));
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
@ -72,6 +72,6 @@ class ShortUrlTest extends TestCase
|
||||
public function provideLengths(): iterable
|
||||
{
|
||||
yield [null, DEFAULT_SHORT_CODES_LENGTH];
|
||||
yield from map(range(1, 10), fn (int $value) => [$value, $value]);
|
||||
yield from map(range(4, 10), fn (int $value) => [$value, $value]);
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,9 @@ class ShortUrlMetaTest extends TestCase
|
||||
ShortUrlMetaInputFilter::VALID_UNTIL => 500,
|
||||
ShortUrlMetaInputFilter::DOMAIN => 4,
|
||||
]];
|
||||
yield [[
|
||||
ShortUrlMetaInputFilter::SHORT_CODE_LENGTH => 3,
|
||||
]];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
Loading…
Reference in New Issue
Block a user