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

Function format_float broken when decsep is '~' (tilde)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.4.5, 3.6, 3.7, 3.8
    • Fix Version/s: 3.6.5, 3.7.1
    • Component/s: General
    • Labels:
    • Database:
      Any
    • Testing Instructions:
      Hide

      Automated testing

      1. Run the automated tests and verify that the format_float test in core_moodlelib_testcase completes with success.

      Manual testing

      1. Set decsep to '~' in a language file for your currently enabled language.
      2. Ensure that the change is picked up (by flushing the language strings cache or updating version.php).
      3. Put the following test code into a script file (named mytestscript.php below) and run it with PHP from the command line.

        <?php
        require('/path/to/config.php'); // causes inclusion of moodlelib.php
        echo format_float(1.234, 5, true, true);
        

      4. Run the script:

        php mytestscript.php

      5. Check the test result:
        • Ensure that you do not see the following warning:

          PHP Warning: preg_replace(): Unknown modifier ')' in /path/to/format_float_test.php on line <linenumber>

        • Verify that you see the following output:
          1~234
          (No PHP warning message.)
      Show
      Automated testing Run the automated tests and verify that the format_float test in core_moodlelib_testcase completes with success. Manual testing Set decsep to '~' in a language file for your currently enabled language. Ensure that the change is picked up (by flushing the language strings cache or updating version.php ). Put the following test code into a script file (named mytestscript.php below) and run it with PHP from the command line. <?php require ( '/path/to/config.php' ); // causes inclusion of moodlelib.php echo format_float(1.234, 5, true, true); Run the script: php mytestscript.php Check the test result: Ensure that you do not see the following warning: PHP Warning: preg_replace(): Unknown modifier ')' in /path/to/format_float_test.php on line <linenumber> Verify that you see the following output: 1~234 (No PHP warning message.)
    • Workaround:
      Hide

      Do not use a tilde ('~') as the decsep string.

      Show
      Do not use a tilde ( '~' ) as the decsep string.
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_34_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
    • Fixed Branches:
      MOODLE_36_STABLE, MOODLE_37_STABLE
    • Pull 3.5 Branch:
    • Pull 3.6 Branch:
    • Pull 3.7 Branch:
    • Pull Master Branch:
      MDL-64975-master

      Description

      Bug description

      Function format_float in lib/moodlelib.php does not work properly when the string decsep is set to a tilde character ('~').

      First release in which this bug appeared: Moodle 2.3
      Introduced in commit: 637da99edbd7258fae20374ed8c890a167f40d30

      Source of the problem

      Incorrect usage of function preg_quote.

      How to fix

      Replace

      preg_quote($separator)

      with

      preg_quote($separator, '~')

      in function format_float.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                8/Jul/19

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 15 minutes
                1h 15m