Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-46701

Base event JSON encoding decoding check can fail for any float values.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.6.4, 2.7.1
    • Fix Version/s: BACKEND
    • Component/s: Events API
    • Labels:
    • Affected Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE

      Description

      In MDL-43175, the comparison of event data with its decoded equivalent was relaxed so that floats which happened to be whole numbers would not throw unwanted debugging messages, but this comparison can fail for any float.

      To replicate, add the following to lib/tests/event_test.php in the test_problematic_events() function:

      // Check that other float numbers do not trigger debugging messages.
              $event8 = \core_tests\event\unittest_executed::create(array('courseid'=>1, 'context'=>\context_system::instance(),
                      'other' => array('starttime' => microtime(true), 'wholenumber' => 90.0000, 'numberwithdecimals' => 54.7656, 'sample' => 1)));
              $event8->trigger();
              $this->assertDebuggingNotCalled();
      

      The PHP documentation says "do not compare floating point numbers directly for equality" (http://php.net/manual/en/language.types.float.php)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              maherne Michael Aherne
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: