From 7fdb69b012cf394c428400d7ec1827dbedaf2924 Mon Sep 17 00:00:00 2001 From: Jan Wennrich <jan@pcsg.de> Date: Thu, 1 Feb 2018 14:44:48 +0100 Subject: [PATCH] fix: escape dots in TLDs for regex expression --- src/QUI/AmazonAffiliate/LinkParser.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/QUI/AmazonAffiliate/LinkParser.php b/src/QUI/AmazonAffiliate/LinkParser.php index 1c9a860..7618350 100644 --- a/src/QUI/AmazonAffiliate/LinkParser.php +++ b/src/QUI/AmazonAffiliate/LinkParser.php @@ -30,7 +30,7 @@ class LinkParser $Config = \QUI::getPackage('quiqqer/amazon-affiliate')->getConfig(); // Turn domains into regex OR expression (e.g. "de|at|com|co.uk" - $domainsRegex = implode('|', self::DOMAINS); + $domainsRegex = str_replace('.','\.', implode('|', self::DOMAINS)); // Regex gets for all Amazon URLs and their paths under the above defined domains $string = preg_replace_callback( @@ -62,6 +62,21 @@ class LinkParser $string ); + $string = preg_replace_callback( + "/(?<preview><div data-oembed-url=\"(?<url>http(?:s)?:\/\/(?:www\.)?amazon\.(?<domain>de|com|at|co\.uk)\/[\d\w-\._~:\/\?#\[\]@!$&'\(\)\*+,;=`]*)\">.*<\/script>.*<\/div>)/isU", + function ($matches) { + // $matches['url'] contains the whole URL and $matches['domain'] contains the TLD (de, com, etc.) + + $url = $matches['url']; + $preview = $matches['preview']; + + $replacement = "<a href=\"$url\">$preview</a>"; + + return $replacement; + }, + $string + ); + return $string; } } -- GitLab