From 6d366188c98d0aa0621d03b38b2ba6dacb575b08 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 22 Oct 2019 19:37:35 +0200 Subject: [PATCH 1/3] Added github funding --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 3f217e2f..53e16c98 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,2 @@ +github: ['acelaya'] custom: ['https://acel.me/donate'] From cd6f067fe579ba00601bc3650c6003a6e41d0641 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 22 Oct 2019 19:43:53 +0200 Subject: [PATCH 2/3] Ensured domain is taken into account when generating QR codes --- module/Core/src/Action/QrCodeAction.php | 4 +++- module/Core/src/Service/UrlShortener.php | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index ef294265..d03e4c4d 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -59,8 +59,10 @@ class QrCodeAction implements MiddlewareInterface { // Make sure the short URL exists for this short code $shortCode = $request->getAttribute('shortCode'); + $domain = $request->getUri()->getAuthority(); + try { - $this->urlShortener->shortCodeToUrl($shortCode); + $this->urlShortener->shortCodeToUrl($shortCode, $domain); } catch (InvalidShortCodeException | EntityDoesNotExistException $e) { $this->logger->warning('An error occurred while creating QR code. {e}', ['e' => $e]); return $this->buildErrorResponse($request, $handler); diff --git a/module/Core/src/Service/UrlShortener.php b/module/Core/src/Service/UrlShortener.php index f282ba54..d286069e 100644 --- a/module/Core/src/Service/UrlShortener.php +++ b/module/Core/src/Service/UrlShortener.php @@ -152,6 +152,7 @@ class UrlShortener implements UrlShortenerInterface if ($shortUrl === null) { throw EntityDoesNotExistException::createFromEntityAndConditions(ShortUrl::class, [ 'shortCode' => $shortCode, + 'domain' => $domain, ]); } From f784ee5b28f582537e164cb3def607d476959a53 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 22 Oct 2019 19:52:28 +0200 Subject: [PATCH 3/3] Fixed unit tests --- CHANGELOG.md | 1 + module/Core/test/Action/QrCodeActionTest.php | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7cba34c..f6e2556b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this * [#507](https://github.com/shlinkio/shlink/issues/507) Fixed error with too long original URLs by increasing size to the maximum value (2048) based on [the standard](https://stackoverflow.com/a/417184). * [#502](https://github.com/shlinkio/shlink/issues/502) Fixed error when providing the port as part of the domain on short URLs. +* [#509](https://github.com/shlinkio/shlink/issues/509) Fixed error when trying to generate a QR code for a short URL which uses a custom domain. ## 1.19.0 - 2019-10-05 diff --git a/module/Core/test/Action/QrCodeActionTest.php b/module/Core/test/Action/QrCodeActionTest.php index b6cab5a7..ddb062dd 100644 --- a/module/Core/test/Action/QrCodeActionTest.php +++ b/module/Core/test/Action/QrCodeActionTest.php @@ -36,11 +36,11 @@ class QrCodeActionTest extends TestCase } /** @test */ - public function aNotFoundShortCodeWillDelegateIntoNextMiddleware() + public function aNotFoundShortCodeWillDelegateIntoNextMiddleware(): void { $shortCode = 'abc123'; - $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class) - ->shouldBeCalledOnce(); + $this->urlShortener->shortCodeToUrl($shortCode, '')->willThrow(EntityDoesNotExistException::class) + ->shouldBeCalledOnce(); $delegate = $this->prophesize(RequestHandlerInterface::class); $process = $delegate->handle(Argument::any())->willReturn(new Response()); @@ -50,11 +50,11 @@ class QrCodeActionTest extends TestCase } /** @test */ - public function anInvalidShortCodeWillReturnNotFoundResponse() + public function anInvalidShortCodeWillReturnNotFoundResponse(): void { $shortCode = 'abc123'; - $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class) - ->shouldBeCalledOnce(); + $this->urlShortener->shortCodeToUrl($shortCode, '')->willThrow(InvalidShortCodeException::class) + ->shouldBeCalledOnce(); $delegate = $this->prophesize(RequestHandlerInterface::class); $process = $delegate->handle(Argument::any())->willReturn(new Response()); @@ -64,11 +64,11 @@ class QrCodeActionTest extends TestCase } /** @test */ - public function aCorrectRequestReturnsTheQrCodeResponse() + public function aCorrectRequestReturnsTheQrCodeResponse(): void { $shortCode = 'abc123'; - $this->urlShortener->shortCodeToUrl($shortCode)->willReturn(new ShortUrl('')) - ->shouldBeCalledOnce(); + $this->urlShortener->shortCodeToUrl($shortCode, '')->willReturn(new ShortUrl('')) + ->shouldBeCalledOnce(); $delegate = $this->prophesize(RequestHandlerInterface::class); $resp = $this->action->process(