aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2022-04-20 10:27:18 +0200
committerEike Ziller <eike.ziller@qt.io>2022-04-21 06:56:56 +0000
commitd1686e18679fd229d2bfa45828a79004cad1e052 (patch)
treefc099c5b39e672693222d33d0ae95928f887a55e
parent98dda165e4007d3eeda9896b21163d79693c94c0 (diff)
UpdateInfo: Fix parsing of update info
It was no longer showing any updates. At some point MaintenanceTool added <?xml...> headers to its responses, which broke our combine-and- parse hack, since such a header in the middle of XML is invalid. Add a hack that removes these headers first. This should be refactored without the use of ShellCommand in master, because that doesn't allow us to access the output of the two jobs separately. Change-Id: I7248b070a8edb1a45248b3531ed50bb0d94eef73 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r--src/plugins/updateinfo/updateinfotools.h8
-rw-r--r--tests/auto/updateinfo/tst_updateinfo.cpp4
2 files changed, 9 insertions, 3 deletions
diff --git a/src/plugins/updateinfo/updateinfotools.h b/src/plugins/updateinfo/updateinfotools.h
index 66ad2eb3ac..c8dd3a7fd0 100644
--- a/src/plugins/updateinfo/updateinfotools.h
+++ b/src/plugins/updateinfo/updateinfotools.h
@@ -31,6 +31,7 @@
#include <QDomDocument>
#include <QList>
#include <QLoggingCategory>
+#include <QRegularExpression>
#include <QVersionNumber>
#include <memory>
@@ -40,8 +41,11 @@ Q_DECLARE_LOGGING_CATEGORY(log)
std::unique_ptr<QDomDocument> documentForResponse(const QString &response)
{
// since the output can contain two toplevel items from the two separate MaintenanceTool runs,
- // surround with a toplevel element
- const QString xml = response.isEmpty() ? QString() : ("<doc>" + response + "</doc>");
+ // clean up any <?xml version="1.0"?> and surround with a toplevel element
+ QString responseWithoutHeader = response;
+ responseWithoutHeader.remove(QRegularExpression("<\\?xml.*\\?>"));
+ const QString xml = response.isEmpty() ? QString()
+ : ("<doc>" + responseWithoutHeader + "</doc>");
std::unique_ptr<QDomDocument> doc(new QDomDocument);
doc->setContent(xml);
return doc;
diff --git a/tests/auto/updateinfo/tst_updateinfo.cpp b/tests/auto/updateinfo/tst_updateinfo.cpp
index 55e61a16c2..1fa1686919 100644
--- a/tests/auto/updateinfo/tst_updateinfo.cpp
+++ b/tests/auto/updateinfo/tst_updateinfo.cpp
@@ -45,9 +45,11 @@ void tst_UpdateInfo::updates_data()
QTest::addColumn<QList<QtPackage>>("xpackages");
QTest::newRow("updates and packages")
- << R"raw(<updates>
+ << R"raw(<?xml version="1.0"?>
+ <updates>
<update name="Qt Design Studio 3.2.0" version="3.2.0-0-202203291247" size="3113234690" id="qt.tools.qtdesignstudio"/>
</updates>
+ <?xml version="1.0"?>
<availablepackages>
<package name="qt.qt6.621" displayname="Qt 6.2.1" version="6.2.1-0-202110220854"/>
<package name="qt.qt5.5152" displayname="Qt 5.15.2" version="5.15.2-0-202011130607" installedVersion="5.15.2-0-202011130607"/>