Fix QUrl::toDisplayString(PreferLocalFile) returning an encoded path
It's supposed to return the same as toLocalFile(), for local files, which means passing QUrl::FullyDecoded just like QUrl::toLocalFile() does. But a few code paths were testing component formatting options without masking other FormattingOptions like RemovePassword, so this had to be fixed. Fixes: QTBUG-84594 Change-Id: I82f15148b6d93516200f9ad6258d474e7f10924a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
76f45e6e97
commit
eb54646984
@ -836,7 +836,8 @@ recodeFromUser(const QString &input, const ushort *actions, int from, int to)
|
|||||||
static inline void appendToUser(QString &appendTo, QStringView value, QUrl::FormattingOptions options,
|
static inline void appendToUser(QString &appendTo, QStringView value, QUrl::FormattingOptions options,
|
||||||
const ushort *actions)
|
const ushort *actions)
|
||||||
{
|
{
|
||||||
if (options == QUrl::PrettyDecoded) {
|
// Test ComponentFormattingOptions, ignore FormattingOptions.
|
||||||
|
if ((options & 0xFFFF0000) == QUrl::PrettyDecoded) {
|
||||||
appendTo += value;
|
appendTo += value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3276,9 +3277,10 @@ QString QUrl::toString(FormattingOptions options) const
|
|||||||
// also catches isEmpty()
|
// also catches isEmpty()
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
if (options == QUrl::FullyDecoded) {
|
if ((options & QUrl::FullyDecoded) == QUrl::FullyDecoded) {
|
||||||
qWarning("QUrl: QUrl::FullyDecoded is not permitted when reconstructing the full URL");
|
qWarning("QUrl: QUrl::FullyDecoded is not permitted when reconstructing the full URL");
|
||||||
options = QUrl::PrettyDecoded;
|
options &= ~QUrl::FullyDecoded;
|
||||||
|
//options |= QUrl::PrettyDecoded; // no-op, value is 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// return just the path if:
|
// return just the path if:
|
||||||
@ -3291,7 +3293,7 @@ QString QUrl::toString(FormattingOptions options) const
|
|||||||
&& (!d->hasQuery() || options.testFlag(QUrl::RemoveQuery))
|
&& (!d->hasQuery() || options.testFlag(QUrl::RemoveQuery))
|
||||||
&& (!d->hasFragment() || options.testFlag(QUrl::RemoveFragment))
|
&& (!d->hasFragment() || options.testFlag(QUrl::RemoveFragment))
|
||||||
&& isLocalFile()) {
|
&& isLocalFile()) {
|
||||||
url = d->toLocalFile(options);
|
url = d->toLocalFile(options | QUrl::FullyDecoded);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,7 +676,7 @@ qt_urlRecode(QString &appendTo, QStringView in,
|
|||||||
QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications)
|
QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications)
|
||||||
{
|
{
|
||||||
uchar actionTable[sizeof defaultActionTable];
|
uchar actionTable[sizeof defaultActionTable];
|
||||||
if (encoding == QUrl::FullyDecoded) {
|
if ((encoding & QUrl::FullyDecoded) == QUrl::FullyDecoded) {
|
||||||
return int(decode(appendTo, in));
|
return int(decode(appendTo, in));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ private slots:
|
|||||||
void toString_PreferLocalFile();
|
void toString_PreferLocalFile();
|
||||||
void toString_constructed_data();
|
void toString_constructed_data();
|
||||||
void toString_constructed();
|
void toString_constructed();
|
||||||
|
void toDisplayString_PreferLocalFile_data();
|
||||||
|
void toDisplayString_PreferLocalFile();
|
||||||
void toAndFromStringList_data();
|
void toAndFromStringList_data();
|
||||||
void toAndFromStringList();
|
void toAndFromStringList();
|
||||||
void isParentOf_data();
|
void isParentOf_data();
|
||||||
@ -1207,6 +1209,32 @@ void tst_QUrl::toString_constructed()
|
|||||||
QCOMPARE(url.toEncoded(formattingOptions), asEncoded);
|
QCOMPARE(url.toEncoded(formattingOptions), asEncoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QUrl::toDisplayString_PreferLocalFile_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QUrl>("url");
|
||||||
|
QTest::addColumn<QString>("string");
|
||||||
|
|
||||||
|
QTest::newRow("basic") << QUrl::fromLocalFile("/home/charles/foomoo")
|
||||||
|
<< QString::fromLatin1("/home/charles/foomoo");
|
||||||
|
QTest::newRow("with%") << QUrl::fromLocalFile("/home/charles/foo%20moo")
|
||||||
|
<< QString::fromLatin1("/home/charles/foo%20moo");
|
||||||
|
QTest::newRow("non-local") << QUrl("file://host/foo")
|
||||||
|
<< QString::fromLatin1("//host/foo");
|
||||||
|
QTest::newRow("query-and-fragment") << QUrl("file://user:pass@example.org/a?b=c%20d%23e#frag%23ment")
|
||||||
|
<< QString::fromLatin1("file://user@example.org/a?b=c d%23e#frag%23ment");
|
||||||
|
QTest::newRow("http") << QUrl("http://user:pass@example.org/a?b=c%20d%23e#frag%23ment")
|
||||||
|
<< QString::fromLatin1("http://user@example.org/a?b=c d%23e#frag%23ment");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QUrl::toDisplayString_PreferLocalFile()
|
||||||
|
{
|
||||||
|
QFETCH(QUrl, url);
|
||||||
|
QFETCH(QString, string);
|
||||||
|
|
||||||
|
if (url.isLocalFile() && url.query().isEmpty() && url.fragment().isEmpty())
|
||||||
|
QCOMPARE(url.toLocalFile(), string);
|
||||||
|
QCOMPARE(url.toDisplayString(QUrl::PreferLocalFile), string);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QUrl::isParentOf()
|
void tst_QUrl::isParentOf()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user