From c21b4b7ff54c155209c508a7799427d326a67069 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 4 Mar 2021 17:37:08 +0000 Subject: [PATCH] MDL-71048 lang: fix null equality check of lang string args. --- lib/moodlelib.php | 2 +- lib/tests/moodlelib_test.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 75ac71f4bde..87ddbe82113 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -10593,7 +10593,7 @@ class lang_string { // changes are not carried across. // To do this we always ensure $a or its properties/values are strings // and that any properties/values that arn't convertable are forgotten. - if (!empty($a)) { + if ($a !== null) { if (is_scalar($a)) { $this->a = $a; } else if ($a instanceof lang_string) { diff --git a/lib/tests/moodlelib_test.php b/lib/tests/moodlelib_test.php index 504128ca514..bc97a15a341 100644 --- a/lib/tests/moodlelib_test.php +++ b/lib/tests/moodlelib_test.php @@ -2132,6 +2132,11 @@ class core_moodlelib_testcase extends advanced_testcase { $this->assertInstanceOf('lang_string', $yes); $this->assertSame($yesexpected, (string)$yes); + // Test lazy loading (returning lang_string) correctly interpolates 0 being used as args. + $numdays = get_string('numdays', 'moodle', 0, true); + $this->assertInstanceOf(lang_string::class, $numdays); + $this->assertSame('0 days', (string) $numdays); + // Test using a lang_string object as the $a argument for a normal // get_string call (returning string). $test = new lang_string('yes', null, null, true);