diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index 9053618014..0e3d317518 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -1391,10 +1391,10 @@ static QCborValue taggedValueFromCbor(QCborStreamReader &reader) auto &e = d->elements[1]; const ByteData *b = d->byteData(e); - auto replaceByteData = [&](const char *buf, qsizetype len) { + auto replaceByteData = [&](const char *buf, qsizetype len, Element::ValueFlags f) { d->data.clear(); d->usedData = 0; - e.flags = Element::HasByteData | Element::StringIsAscii; + e.flags = Element::HasByteData | f; e.value = d->addByteData(buf, len); }; @@ -1414,7 +1414,7 @@ static QCborValue taggedValueFromCbor(QCborStreamReader &reader) } if (dt.isValid()) { QByteArray text = dt.toString(Qt::ISODateWithMs).toLatin1(); - replaceByteData(text, text.size()); + replaceByteData(text, text.size(), Element::StringIsAscii); e.type = QCborValue::String; d->elements[0].value = qint64(QCborKnownTags::DateTimeString); type = QCborValue::DateTime; @@ -1430,7 +1430,7 @@ static QCborValue taggedValueFromCbor(QCborStreamReader &reader) b->asQStringRaw() : b->toUtf8String()); QByteArray encoded = url.toString(QUrl::DecodeReserved).toUtf8(); - replaceByteData(encoded, encoded.size()); + replaceByteData(encoded, encoded.size(), {}); } type = QCborValue::Url; } @@ -1449,7 +1449,7 @@ static QCborValue taggedValueFromCbor(QCborStreamReader &reader) char buf[sizeof(QUuid)] = {}; if (b) memcpy(buf, b->byte(), qMin(sizeof(buf), size_t(b->len))); - replaceByteData(buf, sizeof(buf)); + replaceByteData(buf, sizeof(buf), {}); type = QCborValue::Uuid; } diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index c6733205e5..ffc22bc9a3 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -1391,6 +1391,9 @@ static void addCommonCborData() QTest::newRow("Url") << QCborValue(QUrl("HTTPS://example.com/{%30%31}?q=%3Ca+b%20%C2%A9%3E&%26")) << raw("\xd8\x20\x78\x27" "https://example.com/{01}?q=&%26") << noxfrm; + QTest::newRow("Url:NonAscii") << QCborValue(QUrl("https://example.com/\xc2\xa0")) + << raw("\xd8\x20\x76" "https://example.com/\xc2\xa0") + << noxfrm; QTest::newRow("Regex:Empty") << QCborValue(QRegularExpression()) << raw("\xd8\x23\x60") << noxfrm; QTest::newRow("Regex") << QCborValue(QRegularExpression("^.*$")) << raw("\xd8\x23\x64" "^.*$") << noxfrm;