Multibyte comments broken

Bug #1836588 reported by Mitsuhiro Yoshida
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
High
Unassigned
19.04
Fix Released
High
Unassigned
19.10
Fix Released
High
Unassigned

Bug Description

When we post English and Japanese comments on a page "Add comment" field, only Japanese characters are corrupted as the attached screenshot (mahara_comment.png).

We can fix the issue using mb_convert_encoding function as below. Hopefully this fix helps Mahara multibyte character users.

---------------------------

Program file to modify:
artefact/comment/lib.php

Line number to modify;
1184

[ Before ]
    /*
     * Removes the classes from the text of the comment that could interfere
     * with the comment display
     * @param string $comment the text content of the comment
     */
    public static function remove_comments_classes($comment) {

        if (empty($comment)) {
            return "";
        }
        $dom = new DOMDocument();
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        $dom->loadHTML($comment, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
        $xpath = new DOMXPath($dom);

[ After ]
    /*
     * Removes the classes from the text of the comment that could interfere
     * with the comment display
     * @param string $comment the text content of the comment
     */
    public static function remove_comments_classes($comment) {

        if (empty($comment)) {
            return "";
        }
        $dom = new DOMDocument();
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
// $dom->loadHTML($comment, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
        if (function_exists('mb_convert_encoding')) {
            $dom->loadHTML(mb_convert_encoding($comment, 'HTML-ENTITIES', 'UTF-8'));
        } else {
            $dom->loadHTML($comment, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
        }
        $xpath = new DOMXPath($dom);

Revision history for this message
Mitsuhiro Yoshida (mits) wrote :
Changed in mahara:
importance: Undecided → High
Mitsuhiro Yoshida (mits)
description: updated
Revision history for this message
Mitsuhiro Yoshida (mits) wrote :
Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

Thank you Mits. We'll add this to our code review.

If you like, you can connect to the Mahara code review yourself in order to submit your patches straight into it. Instructions are available at https://wiki.mahara.org/wiki/Developer_Area/Contributing_Code

Changed in mahara:
status: New → In Progress
Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/10315

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/10315
Committed: https://git.mahara.org/mahara/mahara/commit/ad1143dd1e452f9d28a55b613f4e10572fd510a3
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit ad1143dd1e452f9d28a55b613f4e10572fd510a3
Author: Mitsuhiro Yoshida <email address hidden>
Date: Mon Sep 9 11:42:29 2019 +1200

Bug 1836588: Fix errors japanese character encoding

behatnotneeded

Change-Id: Ie65a2da1c4a6dadb05fb46d00feefb39a09bd754

Robert Lyon (robertl-9)
Changed in mahara:
status: In Progress → Fix Committed
Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "19.04_STABLE" branch: https://reviews.mahara.org/10361

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/10361
Committed: https://git.mahara.org/mahara/mahara/commit/f77fce6b2bfd0260ed3a570cae175f8a68f7441a
Submitter: Robert Lyon (<email address hidden>)
Branch: 19.04_STABLE

commit f77fce6b2bfd0260ed3a570cae175f8a68f7441a
Author: Mitsuhiro Yoshida <email address hidden>
Date: Mon Sep 9 11:42:29 2019 +1200

Bug 1836588: Fix errors japanese character encoding

behatnotneeded

Change-Id: Ie65a2da1c4a6dadb05fb46d00feefb39a09bd754
(cherry picked from commit ad1143dd1e452f9d28a55b613f4e10572fd510a3)

Revision history for this message
Mitsuhiro Yoshida (mits) wrote :

Thank you Kristina.

I'll try the Mahara code review (https://wiki.mahara.org/wiki/Developer_Area/Contributing_Code) next time.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.