Merge pull request #1679 from acelaya-forks/feature/deprecate-url-validation

Deprecated validateUrl option on short URL creation/edition
This commit is contained in:
Alejandro Celaya 2023-01-23 20:45:13 +01:00 committed by GitHub
commit 87007677ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 23 additions and 7 deletions

View File

@ -28,7 +28,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* *Nothing* * *Nothing*
### Deprecated ### Deprecated
* [#1676](https://github.com/shlinkio/shlink/issues/1676) Deprecated `GET /short-urls/shorten` endpoint. Use `POST /short-urls` to create short URLs instead * [#1676](https://github.com/shlinkio/shlink/issues/1676) Deprecated `GET /short-urls/shorten` endpoint. Use `POST /short-urls` to create short URLs instead.
* [#1678](https://github.com/shlinkio/shlink/issues/1678) Deprecated `validateUrl` option on URL creation/edition.
### Removed ### Removed
* *Nothing* * *Nothing*

View File

@ -24,7 +24,8 @@
"nullable": true "nullable": true
}, },
"validateUrl": { "validateUrl": {
"description": "Tells if the long URL (if provided) should or should not be validated as a reachable URL. If not provided, it will fall back to app-level config", "deprecated": true,
"description": "**[DEPRECATED]** Tells if the long URL should or should not be validated as a reachable URL. Defaults to `false`",
"type": "boolean" "type": "boolean"
}, },
"tags": { "tags": {

View File

@ -314,10 +314,6 @@
"shortCodeLength": { "shortCodeLength": {
"description": "The length for generated short code. It has to be at least 4 and defaults to 5. It will be ignored when customSlug is provided", "description": "The length for generated short code. It has to be at least 4 and defaults to 5. It will be ignored when customSlug is provided",
"type": "number" "type": "number"
},
"validateUrl": {
"description": "Tells if the long URL should or should not be validated as a reachable URL. If not provided, it will fall back to app-level config",
"type": "boolean"
} }
} }
} }

View File

@ -103,7 +103,7 @@ class CreateShortUrlCommand extends Command
'validate-url', 'validate-url',
null, null,
InputOption::VALUE_NONE, InputOption::VALUE_NONE,
'Forces the long URL to be validated, regardless what is globally configured.', '[DEPRECATED] Makes the URL to be validated as publicly accessible.',
) )
->addOption( ->addOption(
'crawlable', 'crawlable',

View File

@ -14,6 +14,8 @@ class ShortUrlTitleResolutionHelper implements ShortUrlTitleResolutionHelperInte
} }
/** /**
* @deprecated TODO Rename to processTitle once URL validation is removed with Shlink 4.0.0
* Move relevant logic from URL validator here.
* @template T of TitleResolutionModelInterface * @template T of TitleResolutionModelInterface
* @param T $data * @param T $data
* @return T * @return T

View File

@ -9,6 +9,7 @@ use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
interface ShortUrlTitleResolutionHelperInterface interface ShortUrlTitleResolutionHelperInterface
{ {
/** /**
* @deprecated TODO Rename to processTitle once URL validation is removed with Shlink 4.0.0
* @template T of TitleResolutionModelInterface * @template T of TitleResolutionModelInterface
* @param T $data * @param T $data
* @return T * @return T

View File

@ -10,6 +10,7 @@ interface TitleResolutionModelInterface
public function getLongUrl(): string; public function getLongUrl(): string;
/** @deprecated */
public function doValidateUrl(): bool; public function doValidateUrl(): bool;
public function withResolvedTitle(string $title): static; public function withResolvedTitle(string $title): static;

View File

@ -33,6 +33,7 @@ final class ShortUrlCreation implements TitleResolutionModelInterface
public readonly bool $findIfExists = false, public readonly bool $findIfExists = false,
public readonly ?string $domain = null, public readonly ?string $domain = null,
public readonly int $shortCodeLength = 5, public readonly int $shortCodeLength = 5,
/** @deprecated */
public readonly bool $validateUrl = false, public readonly bool $validateUrl = false,
public readonly ?ApiKey $apiKey = null, public readonly ?ApiKey $apiKey = null,
public readonly array $tags = [], public readonly array $tags = [],
@ -131,6 +132,7 @@ final class ShortUrlCreation implements TitleResolutionModelInterface
return $this->domain !== null; return $this->domain !== null;
} }
/** @deprecated */
public function doValidateUrl(): bool public function doValidateUrl(): bool
{ {
return $this->validateUrl; return $this->validateUrl;

View File

@ -38,6 +38,7 @@ final class ShortUrlEdition implements TitleResolutionModelInterface
private readonly bool $titlePropWasProvided = false, private readonly bool $titlePropWasProvided = false,
public readonly ?string $title = null, public readonly ?string $title = null,
public readonly bool $titleWasAutoResolved = false, public readonly bool $titleWasAutoResolved = false,
/** @deprecated */
public readonly bool $validateUrl = false, public readonly bool $validateUrl = false,
private readonly bool $crawlablePropWasProvided = false, private readonly bool $crawlablePropWasProvided = false,
public readonly bool $crawlable = false, public readonly bool $crawlable = false,
@ -154,6 +155,7 @@ final class ShortUrlEdition implements TitleResolutionModelInterface
return $this->titleWasAutoResolved; return $this->titleWasAutoResolved;
} }
/** @deprecated */
public function doValidateUrl(): bool public function doValidateUrl(): bool
{ {
return $this->validateUrl; return $this->validateUrl;

View File

@ -32,6 +32,7 @@ class ShortUrlInputFilter extends InputFilter
public const SHORT_CODE_LENGTH = 'shortCodeLength'; public const SHORT_CODE_LENGTH = 'shortCodeLength';
public const LONG_URL = 'longUrl'; public const LONG_URL = 'longUrl';
public const DEVICE_LONG_URLS = 'deviceLongUrls'; public const DEVICE_LONG_URLS = 'deviceLongUrls';
/** @deprecated */
public const VALIDATE_URL = 'validateUrl'; public const VALIDATE_URL = 'validateUrl';
public const API_KEY = 'apiKey'; public const API_KEY = 'apiKey';
public const TAGS = 'tags'; public const TAGS = 'tags';

View File

@ -22,6 +22,7 @@ use function trim;
use const Shlinkio\Shlink\TITLE_TAG_VALUE; use const Shlinkio\Shlink\TITLE_TAG_VALUE;
/** @deprecated */
class UrlValidator implements UrlValidatorInterface, RequestMethodInterface class UrlValidator implements UrlValidatorInterface, RequestMethodInterface
{ {
private const MAX_REDIRECTS = 15; private const MAX_REDIRECTS = 15;
@ -33,6 +34,7 @@ class UrlValidator implements UrlValidatorInterface, RequestMethodInterface
} }
/** /**
* @deprecated
* @throws InvalidUrlException * @throws InvalidUrlException
*/ */
public function validateUrl(string $url, bool $doValidate): void public function validateUrl(string $url, bool $doValidate): void
@ -44,6 +46,10 @@ class UrlValidator implements UrlValidatorInterface, RequestMethodInterface
$this->validateUrlAndGetResponse($url); $this->validateUrlAndGetResponse($url);
} }
/**
* @deprecated
* @throws InvalidUrlException
*/
public function validateUrlWithTitle(string $url, bool $doValidate): ?string public function validateUrlWithTitle(string $url, bool $doValidate): ?string
{ {
if (! $doValidate && ! $this->options->autoResolveTitles) { if (! $doValidate && ! $this->options->autoResolveTitles) {

View File

@ -6,14 +6,17 @@ namespace Shlinkio\Shlink\Core\Util;
use Shlinkio\Shlink\Core\Exception\InvalidUrlException; use Shlinkio\Shlink\Core\Exception\InvalidUrlException;
/** @deprecated */
interface UrlValidatorInterface interface UrlValidatorInterface
{ {
/** /**
* @deprecated
* @throws InvalidUrlException * @throws InvalidUrlException
*/ */
public function validateUrl(string $url, bool $doValidate): void; public function validateUrl(string $url, bool $doValidate): void;
/** /**
* @deprecated
* @throws InvalidUrlException * @throws InvalidUrlException
*/ */
public function validateUrlWithTitle(string $url, bool $doValidate): ?string; public function validateUrlWithTitle(string $url, bool $doValidate): ?string;