From 1fa1916552030588ab8fecc391da7dc57f97bbab Mon Sep 17 00:00:00 2001 From: Sybille Peters Date: Sun, 15 Dec 2019 15:55:36 +0100 Subject: [PATCH] [BUGFIX] Convert URLs with ampersands in Linkvalidator The linkref functions return the URLs as they are displayed in the BE form. This will return '&' as '&' HTML entity. Linkvalidator should correctly decode the HTML entity. Resolves: #89488 Resolves: #89682 Releases: master, 9.5 Change-Id: I17b421354d45297423437373b92a93dfbe53d2d9 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62645 Tested-by: TYPO3com Tested-by: Susanne Moog Tested-by: Daniel Goerz Reviewed-by: Susanne Moog Reviewed-by: Daniel Goerz --- .../Classes/Linktype/ExternalLinktype.php | 2 +- .../Tests/Unit/Linktype/ExternalLinktypeTest.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php b/typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php index 3b6f5362f077..d1293a69c99a 100644 --- a/typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php +++ b/typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php @@ -220,7 +220,7 @@ public function fetchType($value, $type, $key) protected function preprocessUrl(string $url): string { try { - return (new IdnaConvert())->encodeUri($url); + return (new IdnaConvert())->encodeUri(html_entity_decode($url)); } catch (\Exception $e) { // in case of any error, return empty url. $this->errorParams['errorType'] = 'exception'; diff --git a/typo3/sysext/linkvalidator/Tests/Unit/Linktype/ExternalLinktypeTest.php b/typo3/sysext/linkvalidator/Tests/Unit/Linktype/ExternalLinktypeTest.php index f8af91d99f1d..ddbc95106ca1 100644 --- a/typo3/sysext/linkvalidator/Tests/Unit/Linktype/ExternalLinktypeTest.php +++ b/typo3/sysext/linkvalidator/Tests/Unit/Linktype/ExternalLinktypeTest.php @@ -128,6 +128,16 @@ private function getRequestHeaderOptions(): array public function preprocessUrlsDataProvider() { + // regression tests for issues #89488, #89682 + yield 'URL with query parameter and ampersand' => [ + 'https://standards.cen.eu/dyn/www/f?p=204:6:0::::FSP_ORG_ID,FSP_LANG_ID:,22&cs=1A3FFBC44FAB6B2A181C9525249C3A829', + 'https://standards.cen.eu/dyn/www/f?p=204:6:0::::FSP_ORG_ID,FSP_LANG_ID:,22&cs=1A3FFBC44FAB6B2A181C9525249C3A829' + ]; + yield 'URL with query parameter and ampersand with HTML entities' => [ + 'https://standards.cen.eu/dyn/www/f?p=204:6:0::::FSP_ORG_ID,FSP_LANG_ID:,22&cs=1A3FFBC44FAB6B2A181C9525249C3A829', + 'https://standards.cen.eu/dyn/www/f?p=204:6:0::::FSP_ORG_ID,FSP_LANG_ID:,22&cs=1A3FFBC44FAB6B2A181C9525249C3A829' + ]; + // regression tests for #89378 yield 'URL with path with dashes' => [ 'https://example.com/Unternehmen/Ausbildung-Qualifikation/Weiterbildung-in-Niedersachsen/', @@ -141,9 +151,9 @@ public function preprocessUrlsDataProvider() 'http://example.com/universitaet/die-uni-im-ueberblick/lageplan/gebaeude/building/120', 'http://example.com/universitaet/die-uni-im-ueberblick/lageplan/gebaeude/building/120' ]; - yield 'URL with path and query parameters' => [ + yield 'URL with path and query parameters (including &, ~,; etc.)' => [ 'http://example.com/tv?bcpid=1701167454001&bckey=AQ~~,AAAAAGL7LqU~,aXlKNnCf9d9Tmck-kOc4PGFfCgHjM5JR&bctid=1040702768001', - 'http://example.com/tv?bcpid=1701167454001&bckey=AQ~~,AAAAAGL7LqU~,aXlKNnCf9d9Tmck-kOc4PGFfCgHjM5JR&bctid=1040702768001' + 'http://example.com/tv?bcpid=1701167454001&bckey=AQ~~,AAAAAGL7LqU~,aXlKNnCf9d9Tmck-kOc4PGFfCgHjM5JR&bctid=1040702768001' ]; // make sure we correctly handle URLs with query parameters and fragment etc.