From f35e3f09c271a68a2b252c08a4933bcfb9d79fd6 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 15 Mar 2021 20:20:33 +0100 Subject: [PATCH] MDL-69474 accessibility: page->url can be not set, protect against that Both in unit tests, but also in other areas (say blocks, for example) it's possible that page->url has not been set yet. So, let's change current code to always check if we have something (page->url) to compare. Note the use of has_set_url() is needed, because page->url is magic method and it doesn't work as expected. Hate magics! --- lib/outputrenderers.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 15aaa8c72b5..3b04d5d992a 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2579,12 +2579,8 @@ class core_renderer extends renderer_base { } // Then wrap it in link if needed. Also we don't wrap it in link if the link redirects to itself. - // It might not return page url in unit test. - if (PHPUNIT_TEST) { - if (!$userpicture->link ) { - return $output; - } - } else if (!$userpicture->link || $this->page->url == $url) { + if (!$userpicture->link || + ($this->page->has_set_url() && $this->page->url == $url)) { // Protect against unset page->url. return $output; }