From c4e6ac585dd4baf4865dd78c1c5b0c916fd2b85e Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Mon, 14 Feb 2022 11:30:13 +0100 Subject: [PATCH] MDL-73868 oauth2: Remove multiple slashes in image URL There is an issue with the current Badgr manifest because the image URL contains double slash which is causing an error when storing it in the database (https://api.test.badgr.com/static//images/logo.png). This issue parses image URL and removes multiple slashes in URL. --- lib/classes/oauth2/discovery/imsbadgeconnect.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/classes/oauth2/discovery/imsbadgeconnect.php b/lib/classes/oauth2/discovery/imsbadgeconnect.php index 5d8fcfa4805..2885f91b90e 100644 --- a/lib/classes/oauth2/discovery/imsbadgeconnect.php +++ b/lib/classes/oauth2/discovery/imsbadgeconnect.php @@ -76,6 +76,8 @@ class imsbadgeconnect extends base_definition { } else if ($key == 'image' && empty($issuer->get('image'))) { // Update the image with the value in the manifest file if it's valid and empty in the issuer. $url = filter_var($value, FILTER_SANITIZE_URL); + // Remove multiple slashes in URL. It will fix the Badgr bug with image URL defined in their manifest. + $url = preg_replace('/([^:])(\/{2,})/', '$1/', $url); if (filter_var($url, FILTER_VALIDATE_URL) !== false) { $issuer->set('image', $url); $issuer->update();