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

Messages are broken for non-latin letters

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      It would be prudent to do these tests on Windows as well. There may be differences in libxml.

      Follow the testing instructions from MDL-37138

      Test sending messages between two users, and put funny characters in the message. You can pick some from here

      Also test the chat module.

      Show
      It would be prudent to do these tests on Windows as well . There may be differences in libxml. Follow the testing instructions from MDL-37138 Test sending messages between two users, and put funny characters in the message. You can pick some from here Also test the chat module.
    • Workaround:
      Hide

      Use:

      $text = mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8');

      before:

      $domdoc = new DOMDocument();

      Show
      Use: $text = mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8'); before: $domdoc = new DOMDocument();
    • Affected Branches:
      MOODLE_31_STABLE
    • Fixed Branches:
      MOODLE_30_STABLE, MOODLE_31_STABLE
    • Pull Master Branch:
      MDL-54853-master
    • Sprint:
      3.2 Sprint 1

      Description

      After last weekly update, messages are not usable, because non-latin letters are broken during filter operation in "/lib/weblib.php" function "format_text", because of this part of the code:

      if ($options['blanktarget']) {
              $domdoc = new DOMDocument();
              $domdoc->loadHTML($text);
              foreach ($domdoc->getElementsByTagName('a') as $link) {
                  if ($link->hasAttribute('target') && strpos($link->getAttribute('target'), '_blank') === false) {
                      continue;
                  }
                  $link->setAttribute('target', '_blank');
                  if (strpos($link->getAttribute('rel'), 'noreferrer') === false) {
                      $link->setAttribute('rel', trim($link->getAttribute('rel') . ' noreferrer'));
                  }
              }
       
              // This regex is nasty and I don't like it. The correct way to solve this is by loading the HTML like so:
              // $domdoc->loadHTML($text, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); however it seems like the libxml
              // version that travis uses doesn't work properly and ends up leaving <html><body>, so I'm forced to use
              // this regex to remove those tags.
              $text = trim(preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $domdoc->saveHTML()));
          }
      

        Attachments

        1. actual.png
          actual.png
          7 kB
        2. expected.png
          expected.png
          7 kB

          Issue Links

            Activity

              People

              Assignee:
              cameron1729 cameron1729
              Reporter:
              evsoldatkin Evgeny Soldatkin
              Peer reviewer:
              Marina Glancy
              Integrator:
              Andrew Nicols
              Tester:
              Andrew Nicols
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                11/Jul/16