mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-26 02:40:41 -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
|
public function stringify(ShortUrl $shortUrl): string
|
||||||
{
|
{
|
||||||
return (new Uri())->withPath($shortUrl->getShortCode())
|
$uriWithoutShortCode = (new Uri())->withScheme($this->domainConfig['schema'] ?? 'http')
|
||||||
->withScheme($this->domainConfig['schema'] ?? 'http')
|
->withHost($this->resolveDomain($shortUrl))
|
||||||
->withHost($this->resolveDomain($shortUrl))
|
->withPath($this->basePath)
|
||||||
->__toString();
|
->__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
|
private function resolveDomain(ShortUrl $shortUrl): string
|
||||||
{
|
{
|
||||||
$domain = $shortUrl->getDomain();
|
return $shortUrl->getDomain()?->getAuthority() ?? $this->domainConfig['hostname'] ?? '';
|
||||||
if ($domain === null) {
|
|
||||||
return $this->domainConfig['hostname'] ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return sprintf('%s%s', $domain->getAuthority(), $this->basePath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,18 @@ class ShortUrlStringifierTest extends TestCase
|
|||||||
$shortUrlWithShortCode('bar'),
|
$shortUrlWithShortCode('bar'),
|
||||||
'http://example.com/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' => [
|
yield 'hostname with base path in config' => [
|
||||||
['hostname' => 'example.com/foo/bar'],
|
['hostname' => 'example.com/foo/bar'],
|
||||||
'',
|
'',
|
||||||
|
Loading…
Reference in New Issue
Block a user