Skip to content

Commit

Permalink
Workaround bug in QtXML: Fix xmlToString when QDomElement contains Un…
Browse files Browse the repository at this point in the history
…icode characters above 0xFFFF
  • Loading branch information
pali committed Aug 14, 2016
1 parent cf4d6e5 commit 8612bc3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/xmpp/xmpp-core/xmlprotocol.cpp
Expand Up @@ -97,6 +97,14 @@ static QString xmlToString(const QDomElement &e, const QString &fakeNS, const QS
QString out;
{
QTextStream ts(&out, QIODevice::WriteOnly);
// NOTE: Workaround for bug in QtXML:
// Qt by default convert low surrogate to XML notation &#x....; and let high in binary!
//
// Qt is calling encode function per UTF-16 codepoint, which means that high and low
// surrogate pairs are encoded separately. So all encoding except UTF-16 will leads
// to damaged Unicode characters above 0xFFFF. Internal QString encoding is UTF-16
// so this should be safe as QString still contains valid Unicode characters.
ts.setCodec("UTF-16");
fake.firstChild().save(ts, 0);
}
// 'clip' means to remove any unwanted (and unneeded) characters, such as a trailing newline
Expand Down

0 comments on commit 8612bc3

Please sign in to comment.