From 6e668bc4204a7b5516f4f963d7a365f7aff3d2e6 Mon Sep 17 00:00:00 2001 From: Sergei Ilinykh Date: Wed, 12 Jun 2024 15:54:21 +0300 Subject: [PATCH] Don't publish vcard's empty lists --- src/xmpp/xmpp-im/xmpp_vcard4.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/xmpp/xmpp-im/xmpp_vcard4.cpp b/src/xmpp/xmpp-im/xmpp_vcard4.cpp index ddcebb16..02f5a809 100644 --- a/src/xmpp/xmpp-im/xmpp_vcard4.cpp +++ b/src/xmpp/xmpp-im/xmpp_vcard4.cpp @@ -118,6 +118,9 @@ namespace { static void serializeList(QDomElement &parent, const TaggedList> &list, const QString &tagName, const QString &innerTagName = QLatin1String("text")) { + if (list.isEmpty()) { + return; + } auto document = parent.ownerDocument(); for (const auto &entry : list) { QDomElement element = document.createElement(tagName); @@ -319,6 +322,9 @@ Address::Address(const QDomElement &element) QDomElement Address::toXmlElement(QDomDocument &document) const { + if (isEmpty()) { + return {}; + } QDomElement addressElement = document.createElement(QLatin1String("adr")); VCardHelper::addTextElement(document, addressElement, QLatin1String("pobox"), pobox); VCardHelper::addTextElement(document, addressElement, QLatin1String("ext"), extaddr); @@ -700,10 +706,11 @@ QDomElement VCard::toXmlElement(QDomDocument &document) const } for (const auto &address : d->addresses) { - QDomElement adrElement = document.createElement(QLatin1String("adr")); - address.parameters.addTo(adrElement); - adrElement.appendChild(address.data.toXmlElement(document)); - vCardElement.appendChild(adrElement); + auto addrEl = address.data.toXmlElement(document); + if (!addrEl.isNull()) { + address.parameters.addTo(addrEl); + vCardElement.appendChild(addrEl); + } } return vCardElement;