candy-chat / candy

JavaScript-based multi-user chat client for XMPP.
http://candy-chat.github.io/candy
MIT License
1.33k stars 370 forks source link

Message parser creates nested anchors in xhtml messages #497

Open mazhe opened 7 years ago

mazhe commented 7 years ago

Hi, it seems that the linkify() part of the message that convert links to ... elements do so with xhtml message, and thus create nested elements.

This is "bad" because 1. this is forbidden by the standard, but 2. some reformatters like the image inliner plugin will have issues with it (displays the images two times).

I did not dwell far in the code, but maybe something like that could be done in util.js to avoid the issue?

--- util.js.orig    2016-12-21 11:31:01.039794000 +0100
+++ util.js 2016-12-21 11:34:00.607994000 +0100
@@ -558,10 +558,11 @@
         * Returns:
         *   (String) Parsed text
         */
-       all: function(text) {
+       all: function(text, isXhtml=false) {
            if(text) {
                text = this.escape(text);
-               text = this.linkify(text);
+               if (isXhtml == false)
+                   text = this.linkify(text);
                text = this.emotify(text);
                text = this.nl2br(text);
            }
@@ -650,7 +651,7 @@
            if(maxLength && currentLength > maxLength) {
                text = text.substring(0, maxLength);
            }
-           text = Candy.Util.Parser.all(text);
+           text = Candy.Util.Parser.all(text, true);
            el = $.parseHTML(text);
        }

(of course, that would mean assuming that xhtml message properly format links in their content...)