mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-76362 core_privacy: Shortcircuit URL rewriting on empty content
This commit is contained in:
parent
a4ea607c24
commit
77a0a535b3
@ -14,17 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file contains the moodle format implementation of the content writer.
|
||||
*
|
||||
* @package core_privacy
|
||||
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @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 <andrew@nicols.co.uk>
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 ?? '');
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user