From 4a76c772d70b0977288b94e2bcdbd7c6893537fb Mon Sep 17 00:00:00 2001
From: "Eloy Lafuente (stronk7)" <stronk7@moodle.org>
Date: Sat, 21 Jan 2023 13:24:00 +0100
Subject: [PATCH] MDL-76362 output: Preserve original behaviour for PHP 8.1

Whenever the page_requirements_manager::js_fix_url()
is called with null url, it must throw an exception and emit 0 warnings.

It's covered by an explicit test:

test_js_fix_url_coding_exception with data set "Provide a null argument"
---
 lib/outputrequirementslib.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php
index e6e02ba8292..3156a3e45dd 100644
--- a/lib/outputrequirementslib.php
+++ b/lib/outputrequirementslib.php
@@ -722,7 +722,7 @@ class page_requirements_manager {
             }
             // The URL is not a Moodle resource.
             return $url;
-        } else if (strpos($url, '/') === 0) {
+        } else if (null !== $url && strpos($url, '/') === 0) {
             // Fix the admin links if needed.
             if ($CFG->admin !== 'admin') {
                 if (strpos($url, "/admin/") === 0) {