Skip to content

Commit

Permalink
qtpaths: generate proper JSON
Browse files Browse the repository at this point in the history
The "manual" generation left a trailing comma in the object definition.
This is illegal, as per RFC 8259:

      object = begin-object [ member *( value-separator member ) ]
               end-object

Hence, the resulting JSON does not get accepted by any parser.

Let's just not do that and use QJsonDocument.

Change-Id: I882486e55f66c52d142638f37584088091bbc123
Pick-to: 6.2 6.5 6.6
Fixes: QTBUG-115124
Reviewed-by: Alexandru Croitor <[email protected]>
Reviewed-by: Alexey Edelev <[email protected]>
  • Loading branch information
dangelog committed Jul 8, 2023
1 parent 7c25358 commit 04f2acf
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions qmake/propertyprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include <iostream>

#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>

QT_BEGIN_NAMESPACE

void qmakePropertyPrinter(const QList<QPair<QString, QString>> &values)
Expand All @@ -22,11 +26,12 @@ void qmakePropertyPrinter(const QList<QPair<QString, QString>> &values)

void jsonPropertyPrinter(const QList<QPair<QString, QString>> &values)
{
std::cout << "{\n";
for (const auto &val : values) {
std::cout << "\"" << qPrintable(val.first) << "\":\"" << qPrintable(val.second) << "\",\n";
}
std::cout << "}\n";
QJsonObject object;
for (const auto &val : values)
object.insert(val.first, val.second);

QJsonDocument document(object);
std::cout << document.toJson().constData();
}

QT_END_NAMESPACE

0 comments on commit 04f2acf

Please sign in to comment.