Strophe character encoding issue

2019-04-25 06:44发布

问题:

I am working on an XMPP client and having an issue with messages being sent/received by Strophe (javascript version).

The issue is messages that contain "special" characters. For instance, if I send:

I'm here.

An external client (i.e. iChat) will display

I'm here.

A strophe client doesn't display anything at all.

If I send that same message from iChat to the strophe client, it displays properly.

Here is the most basic sample code I could come up with:

<html>
<head>
  <script type='text/javascript' src='strophe.min.js'></script>
  <script type='text/javascript'>
    function onConnect(status) {
        if (status == Strophe.Status.CONNECTED) {
            var message = $msg({to: CONTACT_JID, from: JID, type: 'chat'}).c('body').t("I'm here."); ;
            connection.send(message.tree());
        }
    }
    var connection = new Strophe.Connection('http://bosh.metajack.im:5280/xmpp-httpbind');
    connection.connect(JID, PASS, onConnect);
  </script>
</head>
<body></body>
</html>

Thanks in advance for any help.

Edit:

Outbound, it seems Strophe is double encoding. When I type

I'm

it is sending

<body>I&amp;apos;m</body>

Inbound, it appears to not be handling CDATA properly. Any guidance or ideas are appreciated.

回答1:

Ok, based on

https://github.com/metajack/strophejs/issues/54

https://github.com/metajack/strophejs/pull/59

you should remove escaping of the text node. Open non-minimized version of strophe.js file and comment line #846

//text = Strophe.xmlescape(text);