From d386e1405c8d9a6d5593bb22ed674964c660f4f6 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 5 Feb 2021 18:22:54 +0100 Subject: [PATCH] Ensure request is not performed if both title resolution and URL validation are disabled --- module/Core/src/Util/UrlValidator.php | 7 +++++-- module/Core/test/Util/UrlValidatorTest.php | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/module/Core/src/Util/UrlValidator.php b/module/Core/src/Util/UrlValidator.php index 8d05cbe6..62c2bea5 100644 --- a/module/Core/src/Util/UrlValidator.php +++ b/module/Core/src/Util/UrlValidator.php @@ -47,9 +47,12 @@ class UrlValidator implements UrlValidatorInterface, RequestMethodInterface public function validateUrlWithTitle(string $url, ?bool $doValidate): ?string { $doValidate = $doValidate ?? $this->options->isUrlValidationEnabled(); - $response = $this->validateUrlAndGetResponse($url, $doValidate); + if (! $doValidate && ! $this->options->autoResolveTitles()) { + return null; + } - if ($response === null || ! $this->options->autoResolveTitles()) { + $response = $this->validateUrlAndGetResponse($url, $doValidate); + if ($response === null) { return null; } diff --git a/module/Core/test/Util/UrlValidatorTest.php b/module/Core/test/Util/UrlValidatorTest.php index 7c5f7c55..9ef8e94e 100644 --- a/module/Core/test/Util/UrlValidatorTest.php +++ b/module/Core/test/Util/UrlValidatorTest.php @@ -87,6 +87,7 @@ class UrlValidatorTest extends TestCase ): void { $request = $this->httpClient->request(Argument::cetera())->willThrow(ClientException::class); $this->options->validateUrl = $validateUrl; + $this->options->autoResolveTitles = true; $result = $this->urlValidator->validateUrlWithTitle('http://foobar.com/12345/hello?foo=bar', $doValidate); @@ -107,10 +108,10 @@ class UrlValidatorTest extends TestCase $request = $this->httpClient->request(Argument::cetera())->willReturn($this->respWithTitle()); $this->options->autoResolveTitles = false; - $result = $this->urlValidator->validateUrlWithTitle('http://foobar.com/12345/hello?foo=bar', true); + $result = $this->urlValidator->validateUrlWithTitle('http://foobar.com/12345/hello?foo=bar', false); self::assertNull($result); - $request->shouldHaveBeenCalledOnce(); + $request->shouldNotHaveBeenCalled(); } /** @test */