diff --git a/lib/classes/event/base.php b/lib/classes/event/base.php index 48af850098e..904c9f88a72 100644 --- a/lib/classes/event/base.php +++ b/lib/classes/event/base.php @@ -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'])) { diff --git a/lib/tests/event/base_test.php b/lib/tests/event/base_test.php index ed8c8e2ab76..d749c543d2a 100644 --- a/lib/tests/event/base_test.php +++ b/lib/tests/event/base_test.php @@ -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(),