diff --git a/privacy/classes/local/request/moodle_content_writer.php b/privacy/classes/local/request/moodle_content_writer.php
index c50720a6b45..a8d893b8776 100644
--- a/privacy/classes/local/request/moodle_content_writer.php
+++ b/privacy/classes/local/request/moodle_content_writer.php
@@ -14,17 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This file contains the moodle format implementation of the content writer.
- *
- * @package core_privacy
- * @copyright 2018 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
namespace core_privacy\local\request;
-defined('MOODLE_INTERNAL') || die();
-
/**
* The moodle_content_writer is the default Moodle implementation of a content writer.
*
@@ -33,6 +24,7 @@ defined('MOODLE_INTERNAL') || die();
*
* Objects of data are stored as JSON.
*
+ * @package core_privacy
* @copyright 2018 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -168,7 +160,10 @@ class moodle_content_writer implements content_writer {
* @param string $text The text to be processed
* @return string The processed string
*/
- public function rewrite_pluginfile_urls(array $subcontext, $component, $filearea, $itemid, $text) : string {
+ public function rewrite_pluginfile_urls(array $subcontext, $component, $filearea, $itemid, $text): string {
+ if ($text === null || $text === '') {
+ return '';
+ }
// Need to take into consideration the subcontext to provide the full path to this file.
$subcontextpath = '';
if (!empty($subcontext)) {
@@ -179,7 +174,7 @@ class moodle_content_writer implements content_writer {
$returnstring = $path . DIRECTORY_SEPARATOR . $this->get_files_target_url($component, $filearea, $itemid) . '/';
$returnstring = clean_param($returnstring, PARAM_PATH);
- return str_replace('@@PLUGINFILE@@/', $returnstring, $text ?? '');
+ return str_replace('@@PLUGINFILE@@/', $returnstring, $text);
}
/**
diff --git a/privacy/classes/tests/request/content_writer.php b/privacy/classes/tests/request/content_writer.php
index c6e9d3d080f..3a8c64e7e30 100644
--- a/privacy/classes/tests/request/content_writer.php
+++ b/privacy/classes/tests/request/content_writer.php
@@ -381,7 +381,7 @@ class content_writer implements \core_privacy\local\request\content_writer {
* @param string $text The text to be processed
* @return string The processed string
*/
- public function rewrite_pluginfile_urls(array $subcontext, $component, $filearea, $itemid, $text) : string {
+ public function rewrite_pluginfile_urls(array $subcontext, $component, $filearea, $itemid, $text): string {
return str_replace('@@PLUGINFILE@@/', 'files/', $text ?? '');
}
diff --git a/privacy/tests/moodle_content_writer_test.php b/privacy/tests/moodle_content_writer_test.php
index d40736d1d4f..e2d8de216fe 100644
--- a/privacy/tests/moodle_content_writer_test.php
+++ b/privacy/tests/moodle_content_writer_test.php
@@ -1292,6 +1292,18 @@ class moodle_content_writer_test extends advanced_testcase {
*/
public function rewrite_pluginfile_urls_provider() {
return [
+ 'nullcontent' => [
+ 'intro',
+ 0,
+ null,
+ '',
+ ],
+ 'emptycontent' => [
+ 'intro',
+ 0,
+ '',
+ '',
+ ],
'zeroitemid' => [
'intro',
0,