Be less restrictive when validating long URLs

This commit is contained in:
Alejandro Celaya 2023-04-10 18:05:57 +02:00
parent 62488ac4e5
commit 72c4052012
3 changed files with 32 additions and 1 deletions

View File

@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
## [Unreleased]
### Added
* *Nothing*
### Changed
* *Nothing*
### Deprecated
* *Nothing*
### Removed
* *Nothing*
### Fixed
* [#1742](https://github.com/shlinkio/shlink/issues/1742) Fix URLs using schemas which do not contain `//`, like `mailto:`, to no longer be considered valid.
## [3.5.3] - 2023-03-31 ## [3.5.3] - 2023-03-31
### Added ### Added
* *Nothing* * *Nothing*

View File

@ -13,7 +13,7 @@ const DEFAULT_REDIRECT_STATUS_CODE = RedirectStatus::STATUS_302; // Deprecated.
const DEFAULT_REDIRECT_CACHE_LIFETIME = 30; const DEFAULT_REDIRECT_CACHE_LIFETIME = 30;
const LOCAL_LOCK_FACTORY = 'Shlinkio\Shlink\LocalLockFactory'; const LOCAL_LOCK_FACTORY = 'Shlinkio\Shlink\LocalLockFactory';
const TITLE_TAG_VALUE = '/<title[^>]*>(.*?)<\/title>/i'; // Matches the value inside a html title tag const TITLE_TAG_VALUE = '/<title[^>]*>(.*?)<\/title>/i'; // Matches the value inside a html title tag
const LOOSE_URI_MATCHER = '/(.+)\:\/\/(.+)/i'; // Matches anything starting with a schema. const LOOSE_URI_MATCHER = '/(.+)\:(.+)/i'; // Matches anything starting with a schema.
const DEFAULT_QR_CODE_SIZE = 300; const DEFAULT_QR_CODE_SIZE = 300;
const DEFAULT_QR_CODE_MARGIN = 0; const DEFAULT_QR_CODE_MARGIN = 0;
const DEFAULT_QR_CODE_FORMAT = 'png'; const DEFAULT_QR_CODE_FORMAT = 'png';

View File

@ -165,6 +165,20 @@ class ShortUrlCreationTest extends TestCase
yield ['гугл', 'гугл']; yield ['гугл', 'гугл'];
} }
#[Test, DataProvider('provideValidLongUrls')]
public function supportsDifferentTypesOfSchemas(string $longUrl): void
{
$creation = ShortUrlCreation::fromRawData(['longUrl' => $longUrl]);
self::assertEquals($longUrl, $creation->longUrl);
}
public static function provideValidLongUrls(): iterable
{
yield 'mailto' => ['mailto:foo@example.com'];
yield 'file' => ['file:///foo/bar'];
yield 'https' => ['https://example.com'];
}
#[Test, DataProvider('provideTitles')] #[Test, DataProvider('provideTitles')]
public function titleIsCroppedIfTooLong(?string $title, ?string $expectedTitle): void public function titleIsCroppedIfTooLong(?string $title, ?string $expectedTitle): void
{ {