mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-25 18:30:23 -06:00
Ensured emojis in short URLs are not URL-encoded
This commit is contained in:
parent
41d3826c1a
commit
45de3f0128
@ -17,19 +17,17 @@ class ShortUrlStringifier implements ShortUrlStringifierInterface
|
||||
|
||||
public function stringify(ShortUrl $shortUrl): string
|
||||
{
|
||||
return (new Uri())->withPath($shortUrl->getShortCode())
|
||||
->withScheme($this->domainConfig['schema'] ?? 'http')
|
||||
->withHost($this->resolveDomain($shortUrl))
|
||||
->__toString();
|
||||
$uriWithoutShortCode = (new Uri())->withScheme($this->domainConfig['schema'] ?? 'http')
|
||||
->withHost($this->resolveDomain($shortUrl))
|
||||
->withPath($this->basePath)
|
||||
->__toString();
|
||||
|
||||
// The short code needs to be appended to avoid it from being URL-encoded
|
||||
return sprintf('%s/%s', $uriWithoutShortCode, $shortUrl->getShortCode());
|
||||
}
|
||||
|
||||
private function resolveDomain(ShortUrl $shortUrl): string
|
||||
{
|
||||
$domain = $shortUrl->getDomain();
|
||||
if ($domain === null) {
|
||||
return $this->domainConfig['hostname'] ?? '';
|
||||
}
|
||||
|
||||
return sprintf('%s%s', $domain->getAuthority(), $this->basePath);
|
||||
return $shortUrl->getDomain()?->getAuthority() ?? $this->domainConfig['hostname'] ?? '';
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,18 @@ class ShortUrlStringifierTest extends TestCase
|
||||
$shortUrlWithShortCode('bar'),
|
||||
'http://example.com/bar',
|
||||
];
|
||||
yield 'special chars in short code' => [
|
||||
['hostname' => 'example.com'],
|
||||
'',
|
||||
$shortUrlWithShortCode('グーグル'),
|
||||
'http://example.com/グーグル',
|
||||
];
|
||||
yield 'emojis in short code' => [
|
||||
['hostname' => 'example.com'],
|
||||
'',
|
||||
$shortUrlWithShortCode('🦣-🍅'),
|
||||
'http://example.com/🦣-🍅',
|
||||
];
|
||||
yield 'hostname with base path in config' => [
|
||||
['hostname' => 'example.com/foo/bar'],
|
||||
'',
|
||||
|
Loading…
Reference in New Issue
Block a user