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

There are many "json_encode(): Invalid UTF-8 sequence in argument" errors in Apache's error_log file

    XMLWordPrintable

    Details

    • Database:
      Any
    • Testing Instructions:
      Hide

      Use some Chinese character in the course title, then visit these course from navigation menu, apache error_log will show this error.

      You need PHP < 5.4.0

      Show
      Use some Chinese character in the course title, then visit these course from navigation menu, apache error_log will show this error. You need PHP < 5.4.0
    • Affected Branches:
      MOODLE_21_STABLE, MOODLE_24_STABLE
    • Fixed Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      w49_MDL-29442_m25_entityutf8

      Description

      If you visit other course from navigation menu, apache's error_log file will record something like "json_encode(): Invalid UTF-8 sequence in argument". It seems json_encode() function received none utf8 character. Navigation menu can't work sometimes. I found some problematic code in lib/navigationlib.php line 4000:

      lib/navigationlib.php line 4000

      if ($child->forcetitle || $child->title !== $child->text) {
          $attributes['title'] = htmlentities($child->title);
      }

      htmlentities use ISO-8859-1 character set as default, but my course title has Chinese character, after called htmlentities, these Chinese character will not be recognizable any more. I think the code should be changed like this:

      if ($child->forcetitle || $child->title !== $child->text) {
          $attributes['title'] = htmlentities($child->title,null,'UTF-8');
      }

      I found moodle called htmlentities in many places, if these callings use ISO-8859-1 as default charset, the Asia user of moodle will suffer inconvenience. I hope all these callings will be checked carefully.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              skodak Petr Skoda
              Reporter:
              luyanfei Yanfei Lu
              Peer reviewer:
              Sam Hemelryk
              Integrator:
              Sam Hemelryk
              Tester:
              Adrian Greeve
              Participants:
              Component watchers:
              David Mudrák (@mudrd8mz), Helen Foster, Víctor Déniz Falcón, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                14/Jan/13