Cannot add comments in a page

Bug #1843210 reported by Chun CHan
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Mahara
In Progress
Undecided
ian hatton

Bug Description

Hi,

When I added a comment by clicking the "Comment" button in a page, all the contents of my comments were gone and just an empty comment was shown (See the attached screenshot).

I edited and added some text again to this empty comment, it still did not work. It seems that the comments cannot be saved.

I also tried to setup new sites for testing, tested both versions 19.04.0 and 19.04.01, the problem is still there.

My server environment:
Red Hat (RHEL) 6.10
Apache 2.4.39
PHP 7.2.19
MariaDB 10.2.16

Would you please help to check?

Thanks.

Tags: comment
Revision history for this message
Chun CHan (brickbrick) wrote :
description: updated
description: updated
Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

I don't have that problem on demo.mahara.org We'll need to see if we can replicate the problem with MariaDB.

Revision history for this message
ian hatton (muld77) wrote :

Also have this issue, exactly the same as above, comments are blank when subimtted, editing an existing comment (even if made before update) will remove the contents.

Looking in the database the "description" field is empty, if this is populated directly in the databse the comment displays so this not a display issue. Saving it again (through the front end) removes the contents of the description field in the database and removes the comment.

We are running MySQL 5.7 and Centos 6.10 on this site. Other sites on the same server do not share the issue, it happened after the latest update. using rh-php7.0

Revision history for this message
ian hatton (muld77) wrote :

NB, I updated another site on the same server and now that has the same issue. (this was test site with hardly any content).

Here is a trace of the error

[WAR] cc (artefact/comment/lib.php:1187) Use of undefined constant LIBXML_HTML_NOIMPLIED - assumed 'LIBXML_HTML_NOIMPLIED'
Call stack (most recent first):

    log_message(string(size 81), integer, true, true, string(size 52), integer) at /home/tdmmahara/public_html/lib/errors.php:520
    error(integer, string(size 81), string(size 52), integer, array(size 2)) at /home/tdmmahara/public_html/artefact/comment/lib.php:1187
    ArtefactTypeComment::remove_comments_classes(string(size 10)) at /home/tdmmahara/public_html/artefact/comment/lib.php:1640
    add_feedback_form_submit(object(Pieform), array(size 7)) at /home/tdmmahara/public_html/lib/pieforms/pieform.php:544
    Pieform->__construct(array(size 9)) at /home/tdmmahara/public_html/lib/pieforms/pieform.php:166
    Pieform::process(array(size 9)) at /home/tdmmahara/public_html/lib/mahara.php:5400
    pieform(array(size 9)) at /home/tdmmahara/public_html/view/view.php:266

[WAR] cc (artefact/comment/lib.php:1187) Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD'
Call stack (most recent first):

    log_message(string(size 79), integer, true, true, string(size 52), integer) at /home/tdmmahara/public_html/lib/errors.php:520
    error(integer, string(size 79), string(size 52), integer, array(size 2)) at /home/tdmmahara/public_html/artefact/comment/lib.php:1187
    ArtefactTypeComment::remove_comments_classes(string(size 10)) at /home/tdmmahara/public_html/artefact/comment/lib.php:1640
    add_feedback_form_submit(object(Pieform), array(size 7)) at /home/tdmmahara/public_html/lib/pieforms/pieform.php:544
    Pieform->__construct(array(size 9)) at /home/tdmmahara/public_html/lib/pieforms/pieform.php:166
    Pieform::process(array(size 9)) at /home/tdmmahara/public_html/lib/mahara.php:5400
    pieform(array(size 9)) at /home/tdmmahara/public_html/view/view.php:266

[WAR] cc (artefact/comment/lib.php:1187) DOMDocument::loadHTML() expects parameter 2 to be integer, string given
Call stack (most recent first):

    log_message(string(size 71), integer, true, true, string(size 52), integer) at /home/tdmmahara/public_html/lib/errors.php:520
    error(integer, string(size 71), string(size 52), integer, array(size 2)) at Unknown:0
    DOMDocument->loadHTML(string(size 10), string(size 21)) at /home/tdmmahara/public_html/artefact/comment/lib.php:1187
    ArtefactTypeComment::remove_comments_classes(string(size 10)) at /home/tdmmahara/public_html/artefact/comment/lib.php:1640
    add_feedback_form_submit(object(Pieform), array(size 7)) at /home/tdmmahara/public_html/lib/pieforms/pieform.php:544
    Pieform->__construct(array(size 9)) at /home/tdmmahara/public_html/lib/pieforms/pieform.php:166
    Pieform::process(array(size 9)) at /home/tdmmahara/public_html/lib/mahara.php:5400
    pieform(array(size 9)) at /home/tdmmahara/public_html/view/view.php:266

Revision history for this message
ian hatton (muld77) wrote :

This appears to be a libxml issues, 2.7.6 is not enough for this to wor, you need 2.7.7, unfortunately many compiles of PHP run with 2.7.6 still, which caused the issues in our case

Removing the LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD part (as below) does allow comments to work again.

// $dom->loadHTML($comment, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$dom->loadHTML($comment);

I've checked the previous version of the code and this is what is actually in there so assume this check is not required. Hopefully someone can confirm but you should be able to safely remove this as per the change above.

Changed in mahara:
assignee: nobody → ian (muld77)
status: New → Confirmed
Revision history for this message
ian hatton (muld77) wrote :

Edit: the above does not quite work yet, watch this space!

Revision history for this message
ian hatton (muld77) wrote :

Workaround below.
This will be required if your libxml is stuck on 2.7.6 and below, if possible the easier fix would be to update to a PHP release which has 2.7.7. If that's not possible the changes below should workaround the issue by using an older method which avoids using the 2.7.7 feature.
You can check your version with
php -i | grep libxml
File location: /artefact/comment/lib.php

    /*
     * public_html/artefact/comment/lib.php
  * 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);
++ $dom->loadHTML($comment);

        $xpath = new DOMXPath($dom);

        $expression = "//div[contains(@class,'modal-docked')]|//div[contains(@class,'modal')]|//div[contains(@class,'modal-dialog')]|//div[contains(@class,'modal-lg')]";

        foreach ($xpath->evaluate($expression) as $section) {
            $section->removeAttribute('class');
        }
++ return preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveHTML()));
-- return $dom->saveHTML();
    }

Note that
return preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $dom->saveHTML());
should work too (slightly shorter version of the above but I've not tested this).

Changed in mahara:
status: Confirmed → In Progress
Revision history for this message
Chun CHan (brickbrick) wrote :

I tried your workaround, it works fine now.

Thank you very much!~

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.