Multibyte comments broken

Bug #1836588 reported by Mitsuhiro Yoshida on 2019-07-15
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Mahara
Status tracked in 19.10
19.04
High
Unassigned
19.10
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);

Mitsuhiro Yoshida (mits) wrote :
Changed in mahara:
importance: Undecided → High
Mitsuhiro Yoshida (mits) on 2019-07-16
description: updated
Mitsuhiro Yoshida (mits) 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

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) on 2019-09-19
Changed in mahara:
status: In Progress → Fix Committed

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)

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  Edit
Everyone can see this information.

Other bug subscribers