From 25f64a2fc4aa7c8cef4ba797248cf79f26c12517 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 1 Oct 2019 22:15:11 +0200 Subject: [PATCH] Added check for domain when matching an existing short URL --- module/Core/src/Entity/ShortUrl.php | 10 ++++------ module/Core/src/Model/ShortUrlMeta.php | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/module/Core/src/Entity/ShortUrl.php b/module/Core/src/Entity/ShortUrl.php index 2e30ba2d..709499df 100644 --- a/module/Core/src/Entity/ShortUrl.php +++ b/module/Core/src/Entity/ShortUrl.php @@ -53,12 +53,7 @@ class ShortUrl extends AbstractEntity $this->validUntil = $meta->getValidUntil(); $this->maxVisits = $meta->getMaxVisits(); $this->shortCode = $meta->getCustomSlug() ?? ''; // TODO logic to calculate short code should be passed somehow - $this->domain = $this->domainToEntity($meta->getDomain(), $domainResolver ?? new SimpleDomainResolver()); - } - - private function domainToEntity(?string $domain, DomainResolverInterface $domainResolver): ?Domain - { - return $domainResolver->resolveDomain($domain); + $this->domain = ($domainResolver ?? new SimpleDomainResolver())->resolveDomain($meta->getDomain()); } public function getLongUrl(): string @@ -170,6 +165,9 @@ class ShortUrl extends AbstractEntity if ($meta->hasMaxVisits() && $meta->getMaxVisits() !== $this->maxVisits) { return false; } + if ($meta->hasDomain() && $meta->getDomain() !== $this->resolveDomain()) { + return false; + } if ($meta->hasValidSince() && ! $meta->getValidSince()->eq($this->validSince)) { return false; } diff --git a/module/Core/src/Model/ShortUrlMeta.php b/module/Core/src/Model/ShortUrlMeta.php index 37dca315..b6d00834 100644 --- a/module/Core/src/Model/ShortUrlMeta.php +++ b/module/Core/src/Model/ShortUrlMeta.php @@ -151,6 +151,11 @@ final class ShortUrlMeta return (bool) $this->findIfExists; } + public function hasDomain(): bool + { + return $this->domain !== null; + } + public function getDomain(): ?string { return $this->domain;