MDL-76493 core: make sure format_string(null) works on PHP 8.1

This commit is contained in:
Marina Glancy 2022-11-26 14:02:32 +01:00
parent 57c1e97bf1
commit e5f862d0b1
2 changed files with 9 additions and 0 deletions

View File

@ -48,6 +48,10 @@ class weblib_test extends advanced_testcase {
// Unicode entities.
$this->assertSame("ᅻ", format_string("ᅻ"));
// Nulls.
$this->assertSame('', format_string(null));
$this->assertSame('', format_string(null, true, ['escape' => false]));
// < and > signs.
$originalformatstringstriptags = $CFG->formatstringstriptags;

View File

@ -1430,6 +1430,11 @@ function reset_text_filters_cache($phpunitreset = false) {
function format_string($string, $striplinks = true, $options = null) {
global $CFG, $PAGE;
if ($string === '' || is_null($string)) {
// No need to do any filters and cleaning.
return '';
}
// We'll use a in-memory cache here to speed up repeated strings.
static $strcache = false;