Merge branch 'MDL-77827-master' of https://github.com/HuongNV13/moodle

This commit is contained in:
Ilya Tregubov 2023-04-18 08:58:33 +08:00
commit 688c9b13d4
2 changed files with 10 additions and 6 deletions

View File

@ -740,9 +740,10 @@ abstract class base implements \IteratorAggregate {
debugging('Number of event data fields must not be changed in event classes', DEBUG_DEVELOPER);
}
$encoded = json_encode($this->data['other']);
// The comparison here is not set to strict as whole float numbers will be converted to integers through JSON encoding /
// decoding and send an unwanted debugging message.
if ($encoded === false or $this->data['other'] != json_decode($encoded, true)) {
// The comparison here is not set to strict. We just need to check if the data is compatible with the JSON encoding
// or not and we don't need to worry about how the data is encoded. Because in some cases, the data can contain
// objects, and objects can be converted to a different format during encoding and decoding.
if ($encoded === false) {
debugging('other event data must be compatible with json encoding', DEBUG_DEVELOPER);
}
if ($this->data['userid'] and !is_number($this->data['userid'])) {

View File

@ -769,16 +769,19 @@ class base_test extends \advanced_testcase {
$event4->trigger();
$this->assertDebuggingNotCalled();
$event5 = \core_tests\event\problematic_event1::create(array('context'=>\context_system::instance(), 'other'=>(object)array('a'=>1)));
// Check the invalid content that cannot be converted to JSON will trigger debugging messages.
$event5 = \core_tests\event\problematic_event1::create(array('context' => \context_system::instance(), 'other' => [
'a' => NAN
]));
$this->assertDebuggingNotCalled();
$event5->trigger();
$this->assertDebuggingCalled();
// Check that moodle_url object does not trigger debugging messages.
$url = new \moodle_url('/admin/');
$event6 = \core_tests\event\problematic_event1::create(array('context'=>\context_system::instance(), 'other'=>array('a'=>$url)));
$this->assertDebuggingNotCalled();
$event6->trigger();
$this->assertDebuggingCalled();
$this->assertDebuggingNotCalled();
// Check that whole float numbers do not trigger debugging messages.
$event7 = \core_tests\event\unittest_executed::create(array('context'=>\context_system::instance(),