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

Encoding problem when converting online submissions to pdf (unoconv)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 3.1.2
    • 3.1.1
    • Assignment
    • Redhat 6
      PHP 5.6
    • MOODLE_31_STABLE
    • MOODLE_31_STABLE
    • MDL-55374-master
    • Hide

      With php5.6:

      Create an assignment submission using online text. Use this text:

      イリノイ州シカゴにて、アイルランド系の家庭に、

      Verify when grading the submission that the text appears correctly in the editpdf panel.

      Show
      With php5.6: Create an assignment submission using online text. Use this text: イリノイ州シカゴにて、アイルランド系の家庭に、 Verify when grading the submission that the text appears correctly in the editpdf panel.

      HTML files created for converting online submissions to pdf for feedback/annotation (unoconv) are wrongly encoded (See attachment).

      To reproduce (unoconv must be configured correctly on your moodle instance) :

      • As a teacher, create an online text assignment
      • As a student, submit a text with special characters like 'éèÉàÀ'
      • As the teacher, go to the grade form of this student's assignment.
        You should see that the text in the annotation is wrongly encoded

      Dug the code a bit and found out what the problem is :

      Function format_text in "lib/weblib.php" is doing one of the proposed solution by appending "'<?xml version="1.0" encoding="UTF-8" ?>' ." to the string, to force loadHTML to work in UTF-8.

      The following code modif would fix the issue :

      diff --git a/mod/assign/feedback/editpdf/classes/document_services.php b/mod/assign/feedback/editpdf/classes/document_services.php
      index 4ada0a7..e348bc5 100644
      --- a/mod/assign/feedback/editpdf/classes/document_services.php
      +++ b/mod/assign/feedback/editpdf/classes/document_services.php
      @@ -119,7 +119,7 @@ EOD;
            */
           protected static function strip_images($html) {
               $dom = new DOMDocument();
      -        $dom->loadHTML($html);
      +        $dom->loadHTML('<?xml version="1.0" encoding="UTF-8" ?>' . $html);
               $images = $dom->getElementsByTagName('img');
               $i = 0;
       
      @@ -135,7 +135,7 @@ EOD;
                   $text = $dom->createTextNode($replacement);
                   $node->parentNode->replaceChild($text, $node);
               }
      -        return $dom->saveHTML();
      +        return trim(preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $dom->saveHTML($dom->documentElement)));
           }
       
           /**
      

        1. MDL-55374_a.png
          84 kB
          Jean-Philippe Gaudreau

            damyon Damyon Wiese
            gaudreaj Jean-Philippe Gaudreau
            Jean-Philippe Gaudreau Jean-Philippe Gaudreau
            Dan Poltawski Dan Poltawski
            Simey Lameze Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.