mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Merge pull request #1620 from acelaya-forks/feature/empty-domain-fix
Feature/empty domain fix
This commit is contained in:
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
* [#1618](https://github.com/shlinkio/shlink/issues/1618) Fixed imported short URLs and visits dates not being set to the target server timezone.
|
* [#1618](https://github.com/shlinkio/shlink/issues/1618) Fixed imported short URLs and visits dates not being set to the target server timezone.
|
||||||
|
* [#1578](https://github.com/shlinkio/shlink/issues/1578) Fixed short URL allowing an empty string as the domain during creation.
|
||||||
|
|
||||||
|
|
||||||
## [3.3.2] - 2022-10-18
|
## [3.3.2] - 2022-10-18
|
||||||
|
|||||||
@@ -78,6 +78,12 @@ function getOptionalBoolFromInputFilter(InputFilter $inputFilter, string $fieldN
|
|||||||
return $value !== null ? (bool) $value : null;
|
return $value !== null ? (bool) $value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getNonEmptyOptionalValueFromInputFilter(InputFilter $inputFilter, string $fieldName): mixed
|
||||||
|
{
|
||||||
|
$value = $inputFilter->getValue($fieldName);
|
||||||
|
return empty($value) ? null : $value;
|
||||||
|
}
|
||||||
|
|
||||||
function arrayToString(array $array, int $indentSize = 4): string
|
function arrayToString(array $array, int $indentSize = 4): string
|
||||||
{
|
{
|
||||||
$indent = str_repeat(' ', $indentSize);
|
$indent = str_repeat(' ', $indentSize);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Helper\TitleResolutionModelInterface;
|
|||||||
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter;
|
use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter;
|
||||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||||
|
|
||||||
|
use function Shlinkio\Shlink\Core\getNonEmptyOptionalValueFromInputFilter;
|
||||||
use function Shlinkio\Shlink\Core\getOptionalBoolFromInputFilter;
|
use function Shlinkio\Shlink\Core\getOptionalBoolFromInputFilter;
|
||||||
use function Shlinkio\Shlink\Core\getOptionalIntFromInputFilter;
|
use function Shlinkio\Shlink\Core\getOptionalIntFromInputFilter;
|
||||||
use function Shlinkio\Shlink\Core\normalizeOptionalDate;
|
use function Shlinkio\Shlink\Core\normalizeOptionalDate;
|
||||||
@@ -74,7 +75,7 @@ final class ShortUrlCreation implements TitleResolutionModelInterface
|
|||||||
$this->maxVisits = getOptionalIntFromInputFilter($inputFilter, ShortUrlInputFilter::MAX_VISITS);
|
$this->maxVisits = getOptionalIntFromInputFilter($inputFilter, ShortUrlInputFilter::MAX_VISITS);
|
||||||
$this->findIfExists = $inputFilter->getValue(ShortUrlInputFilter::FIND_IF_EXISTS);
|
$this->findIfExists = $inputFilter->getValue(ShortUrlInputFilter::FIND_IF_EXISTS);
|
||||||
$this->validateUrl = getOptionalBoolFromInputFilter($inputFilter, ShortUrlInputFilter::VALIDATE_URL) ?? false;
|
$this->validateUrl = getOptionalBoolFromInputFilter($inputFilter, ShortUrlInputFilter::VALIDATE_URL) ?? false;
|
||||||
$this->domain = $inputFilter->getValue(ShortUrlInputFilter::DOMAIN);
|
$this->domain = getNonEmptyOptionalValueFromInputFilter($inputFilter, ShortUrlInputFilter::DOMAIN);
|
||||||
$this->shortCodeLength = getOptionalIntFromInputFilter(
|
$this->shortCodeLength = getOptionalIntFromInputFilter(
|
||||||
$inputFilter,
|
$inputFilter,
|
||||||
ShortUrlInputFilter::SHORT_CODE_LENGTH,
|
ShortUrlInputFilter::SHORT_CODE_LENGTH,
|
||||||
|
|||||||
@@ -146,4 +146,26 @@ class ShortUrlCreationTest extends TestCase
|
|||||||
yield [str_pad('', 600, 'd'), str_pad('', 512, 'd')];
|
yield [str_pad('', 600, 'd'), str_pad('', 512, 'd')];
|
||||||
yield [str_pad('', 800, 'e'), str_pad('', 512, 'e')];
|
yield [str_pad('', 800, 'e'), str_pad('', 512, 'e')];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @dataProvider provideDomains
|
||||||
|
*/
|
||||||
|
public function emptyDomainIsDiscarded(?string $domain, ?string $expectedDomain): void
|
||||||
|
{
|
||||||
|
$meta = ShortUrlCreation::fromRawData([
|
||||||
|
'domain' => $domain,
|
||||||
|
'longUrl' => '',
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertSame($expectedDomain, $meta->getDomain());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideDomains(): iterable
|
||||||
|
{
|
||||||
|
yield 'null domain' => [null, null];
|
||||||
|
yield 'empty domain' => ['', null];
|
||||||
|
yield 'trimmable domain' => [' ', null];
|
||||||
|
yield 'valid domain' => ['doma.in', 'doma.in'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user