matrix-org / matrix-bifrost

General purpose bridging with a variety of backends including libpurple and xmpp.js
Apache License 2.0
163 stars 31 forks source link

XHTML-IM content missing required <body> tag #292

Open sporkbomb opened 3 years ago

sporkbomb commented 3 years ago

According to https://xmpp.org/extensions/xep-0071.html#concepts (and the chapters following it), XHTML-IM content is supposed to be wrapped in a <html/> tag, which must contain one or more <body/> tags.

The root element for including XHTML content within XMPP stanzas is <html/>. This element is qualified by the 'http://jabber.org/protocol/xhtml-im' namespace. From the perspective of XMPP, the wrapper element functions as an XMPP extension element; from the perspective of XHTML, it functions as a wrapper for XHTML 1.0 content qualified by the 'http://www.w3.org/1999/xhtml' namespace. Such XHTML content MUST be contained in one or more <body/> elements qualified by the 'http://www.w3.org/1999/xhtml' namespace and MUST conform to the XHTML-IM Integration Set defined in the following section.

Bifrost (or rather, the xmppjs part of it) wraps XHTML-IM content in the correct <html/> tag, but does not add the required <body/> tag. As an example, suppose you want to embed <a href="https://foo.bar">Click me</a>. This is currently emitted as

<html xmlns='http://jabber.org/protocol/xhtml-im'>
    <a href="https://foo.bar">Click me</a>
</html>

but should instead be emitted as

<html xmlns='http://jabber.org/protocol/xhtml-im'>
    <body xmlns='http://www.w3.org/1999/xhtml'>
        <a href="https://foo.bar">Click me</a>
    </body>
</html>

Please note that this incorrect behavior is also reflected in the test cases in test/xmppjs/test_XHTMLIM.ts.

The current behavior causes clients receiving these XHTML-IM messages to fail to parse them; this includes all clients based on nbxmpp, such as Gajim.

Neustradamus commented 2 years ago

@sporkbomb: @maranda has solved it in this PR. Have you seen?