Fix QCborValue::toCbor with non-ASCII URLs
Found while fixing QTBUG-79196. Change-Id: Ia2aa807ffa8a4c798425fffd15d841657def99af Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
935681eaca
commit
8027fb60dd
@ -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;
|
||||
}
|
||||
|
@ -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=<a+b \xC2\xA9>&%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;
|
||||
|
Loading…
Reference in New Issue
Block a user