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

Encoding problem when converting online submissions to pdf (unoconv)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.1
    • Fix Version/s: 3.1.2
    • Component/s: Assignment
    • Labels:
    • Environment:
      Redhat 6
      PHP 5.6
    • Testing Instructions:
      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.
    • Affected Branches:
      MOODLE_31_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-55374-master

      Description

      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)));
           }
       
           /**
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                12/Sep/16