Fix handling of encoded NULs (%00) in QUrl::fromPercentEncoding
QString::fromUtf8, without an explicit size, (currently) defaults to stopping at the first NUL. That means we need to pass an explicit size. Also take the opportunity to test that QUrl::toPercentEncoding also works with the same data. Change-Id: I79362d67afda624b01ca07b0315b611c4aa3fdda Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: David Faure <faure@kde.org>
This commit is contained in:
parent
44a7330d67
commit
4d1f0ccbf3
@ -2516,7 +2516,8 @@ QUrl QUrl::fromEncoded(const QByteArray &input, ParsingMode mode)
|
|||||||
*/
|
*/
|
||||||
QString QUrl::fromPercentEncoding(const QByteArray &input)
|
QString QUrl::fromPercentEncoding(const QByteArray &input)
|
||||||
{
|
{
|
||||||
return QString::fromUtf8(QByteArray::fromPercentEncoding(input));
|
QByteArray ba = QByteArray::fromPercentEncoding(input);
|
||||||
|
return QString::fromUtf8(ba, ba.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1397,6 +1397,7 @@ void tst_QUrl::compat_decode_data()
|
|||||||
QTest::newRow("HTTPUrl") << QByteArray("http://qt.nokia.com") << QString("http://qt.nokia.com");
|
QTest::newRow("HTTPUrl") << QByteArray("http://qt.nokia.com") << QString("http://qt.nokia.com");
|
||||||
QTest::newRow("HTTPUrlEncoded") << QByteArray("http://qt%20nokia%20com") << QString("http://qt nokia com");
|
QTest::newRow("HTTPUrlEncoded") << QByteArray("http://qt%20nokia%20com") << QString("http://qt nokia com");
|
||||||
QTest::newRow("EmptyString") << QByteArray("") << QString("");
|
QTest::newRow("EmptyString") << QByteArray("") << QString("");
|
||||||
|
QTest::newRow("NulByte") << QByteArray("C%00%0A") << QString::fromLatin1("C\0\n", 3);
|
||||||
QTest::newRow("Task27166") << QByteArray("Fran%C3%A7aise") << QString::fromUtf8("Française");
|
QTest::newRow("Task27166") << QByteArray("Fran%C3%A7aise") << QString::fromUtf8("Française");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1419,6 +1420,7 @@ void tst_QUrl::compat_encode_data()
|
|||||||
QTest::newRow("HTTPUrl") << QString("http://qt.nokia.com") << QByteArray("http%3A//qt.nokia.com");
|
QTest::newRow("HTTPUrl") << QString("http://qt.nokia.com") << QByteArray("http%3A//qt.nokia.com");
|
||||||
QTest::newRow("HTTPUrlEncoded") << QString("http://qt nokia com") << QByteArray("http%3A//qt%20nokia%20com");
|
QTest::newRow("HTTPUrlEncoded") << QString("http://qt nokia com") << QByteArray("http%3A//qt%20nokia%20com");
|
||||||
QTest::newRow("EmptyString") << QString("") << QByteArray("");
|
QTest::newRow("EmptyString") << QString("") << QByteArray("");
|
||||||
|
QTest::newRow("NulByte") << QString::fromLatin1("C\0\n", 3) << QByteArray("C%00%0A");
|
||||||
QTest::newRow("Task27166") << QString::fromUtf8("Française") << QByteArray("Fran%C3%A7aise");
|
QTest::newRow("Task27166") << QString::fromUtf8("Française") << QByteArray("Fran%C3%A7aise");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1427,7 +1429,7 @@ void tst_QUrl::compat_encode()
|
|||||||
QFETCH(QString, decodedString);
|
QFETCH(QString, decodedString);
|
||||||
QFETCH(QByteArray, encodedString);
|
QFETCH(QByteArray, encodedString);
|
||||||
|
|
||||||
QCOMPARE(QUrl::toPercentEncoding(decodedString, "/.").constData(), encodedString.constData());
|
QCOMPARE(QUrl::toPercentEncoding(decodedString, "/."), encodedString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user