mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +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
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// 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;
|
namespace core_privacy\local\request;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The moodle_content_writer is the default Moodle implementation of a content writer.
|
* 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.
|
* Objects of data are stored as JSON.
|
||||||
*
|
*
|
||||||
|
* @package core_privacy
|
||||||
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @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
|
* @param string $text The text to be processed
|
||||||
* @return string The processed string
|
* @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.
|
// Need to take into consideration the subcontext to provide the full path to this file.
|
||||||
$subcontextpath = '';
|
$subcontextpath = '';
|
||||||
if (!empty($subcontext)) {
|
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 = $path . DIRECTORY_SEPARATOR . $this->get_files_target_url($component, $filearea, $itemid) . '/';
|
||||||
$returnstring = clean_param($returnstring, PARAM_PATH);
|
$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
|
* @param string $text The text to be processed
|
||||||
* @return string The processed string
|
* @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 ?? '');
|
return str_replace('@@PLUGINFILE@@/', 'files/', $text ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1292,6 +1292,18 @@ class moodle_content_writer_test extends advanced_testcase {
|
|||||||
*/
|
*/
|
||||||
public function rewrite_pluginfile_urls_provider() {
|
public function rewrite_pluginfile_urls_provider() {
|
||||||
return [
|
return [
|
||||||
|
'nullcontent' => [
|
||||||
|
'intro',
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
'',
|
||||||
|
],
|
||||||
|
'emptycontent' => [
|
||||||
|
'intro',
|
||||||
|
0,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
],
|
||||||
'zeroitemid' => [
|
'zeroitemid' => [
|
||||||
'intro',
|
'intro',
|
||||||
0,
|
0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user