From 0c95b978b4b3b61d4b5235f379e1f72faab0fe0c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 2 Oct 2021 10:45:00 +0200 Subject: [PATCH] Added option in CLI to disable query forwarding when creating Short URLs --- CHANGELOG.md | 3 +++ .../Command/ShortUrl/GenerateShortUrlCommand.php | 16 +++++++++++++++- module/Core/src/Util/UrlValidator.php | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f15fbbdc..9d253e85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this The config generated with the installing tool still has precedence over the env vars, so it cannot be combined. Either you use the tool, or use env vars. * [#1149](https://github.com/shlinkio/shlink/issues/1149) Allowed to set custom defaults for the QR codes. +* [#1112](https://github.com/shlinkio/shlink/issues/1112) Added new option to define if the query string should be forwarded on a per-short URL basis. + + The new `forwardQuery=true|false` param can be provided during short URL creation or edition, via REST API or CLI command, allowing to override the default behavior which makes the query string to always be forwarded. ### Changed * [#1142](https://github.com/shlinkio/shlink/issues/1142) Replaced `doctrine/cache` package with `symfony/cache`. diff --git a/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php index 6ed3e37c..e43b4ec5 100644 --- a/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php @@ -104,7 +104,19 @@ class GenerateShortUrlCommand extends BaseCommand 'no-validate-url', null, InputOption::VALUE_NONE, - 'Forces the long URL to not be validated, regardless what is globally configured.', + '[DEPRECATED] Forces the long URL to not be validated, regardless what is globally configured.', + ) + ->addOption( + 'crawlable', + 'r', + InputOption::VALUE_NONE, + 'Tells if this URL will be included as "Allow" in Shlink\'s robots.txt.', + ) + ->addOption( + 'no-forward-query', + 'w', + InputOption::VALUE_NONE, + 'Disables the forwarding of the query string to the long URL, when the new short URL is visited.', ); } @@ -156,6 +168,8 @@ class GenerateShortUrlCommand extends BaseCommand ShortUrlInputFilter::SHORT_CODE_LENGTH => $shortCodeLength, ShortUrlInputFilter::VALIDATE_URL => $doValidateUrl, ShortUrlInputFilter::TAGS => $tags, + ShortUrlInputFilter::CRAWLABLE => $input->getOption('crawlable'), + ShortUrlInputFilter::FORWARD_QUERY => !$input->getOption('no-forward-query'), ])); $io->writeln([ diff --git a/module/Core/src/Util/UrlValidator.php b/module/Core/src/Util/UrlValidator.php index 5b84c5f8..bd0a5cfb 100644 --- a/module/Core/src/Util/UrlValidator.php +++ b/module/Core/src/Util/UrlValidator.php @@ -32,7 +32,7 @@ class UrlValidator implements UrlValidatorInterface, RequestMethodInterface */ public function validateUrl(string $url, ?bool $doValidate): void { - // If the URL validation is not enabled or it was explicitly set to not validate, skip check + // If the URL validation is not enabled, or it was explicitly set to not validate, skip check $doValidate = $doValidate ?? $this->options->isUrlValidationEnabled(); if (! $doValidate) { return;