qt5base-lts/tests/auto/corelib/serialization
Sona Kurazyan 1df02b5f98 Fix conversions to JSON from QVariant
After reimplementing Qt JSON support on top of CBOR, there were
unintended behavior changes when converting QVariant{, List, Map} to
QJson{Value, Array, List} due to reusing the code for converting
QVariant* types to CBOR types, and from CBOR types to corresponding JSON
types. In particular, conversions from QVariant containing QByteArray to
JSON has been affected: according to RFC 7049, when converting from
CBOR to JSON, raw byte array data must be encoded in base64url when
converting to a JSON string. As a result QVariant* types containing
QByteArray data ended up base64url-encoded when converted to JSON,
instead of converting using QString::fromUtf8() as before.

There were also differences when converting QRegularExpression.

Reverted the behavior changes by adding a flag to internal methods for
converting CBOR to JSON, to distinguish whether the conversion is done
from QVariant* or CBOR types. These methods now will fall back to the old
behavior, if the conversion is done using QJson*::fromVariant*().

Additionally fixed QJsonValue::fromVariant conversion for NaN and
infinities: they should always convert to QJsonValue::Null. This works
correctly when converting from variant to QJsonArray/QJsonObject, but has
been wrong for QJsonValue.

Added more tests to verify the expected behavior.

[ChangeLog][Important Behavior Changes] Restored pre-5.15.0 behavior
when converting from QVariant* to QJson* types. Unforeseen consequences
of changes in 5.15.0 caused QByteArray data to be base64url-encoded; the
handling of QRegularExpression was also unintentionally changed. These
conversions are now reverted to the prior behavior. Additionally fixed
QJsonValue::fromVariant conversions for NaN and infinities: they should
always convert to QJsonValue::Null.

Fixes: QTBUG-84739
Change-Id: Iaee667d00e5363906eedbb67948b7b39c9d0bc78
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2020-08-13 19:36:58 +02:00
..
json Fix conversions to JSON from QVariant 2020-08-13 19:36:58 +02:00
qcborstreamreader CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qcborstreamwriter CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qcborvalue QCborValue: add support for QCOMPARE string output 2020-08-12 21:05:06 -07:00
qcborvalue_json Fix warning when printing of qsizetype 2020-07-26 17:39:31 +02:00
qdatastream CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qdatastream_core_pixmap CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qtextstream CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qxmlstream CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
cborlargedatavalidation.cpp QCborValue: catch overflow in QByteArray when decoding chunked strings 2020-05-07 07:39:26 -07:00
CMakeLists.txt CMake: Regenerate subdir test projects 2020-07-09 09:38:39 +02:00
serialization.pro Exclude tests that need GUI when GUI isn't available 2019-10-25 11:42:09 +02:00