Ensure request is not performed if both title resolution and URL validation are disabled

This commit is contained in:
Alejandro Celaya 2021-02-05 18:22:54 +01:00
parent 608742c2e2
commit d386e1405c
2 changed files with 8 additions and 4 deletions

View File

@ -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;
}

View File

@ -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 */