diff options
-rw-r--r-- | src/corelib/io/qurl.cpp | 10 | ||||
-rw-r--r-- | src/corelib/io/qurlrecode.cpp | 2 | ||||
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 28 |
3 files changed, 35 insertions, 5 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 104161bc33..0c81af52d7 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -834,7 +834,8 @@ recodeFromUser(const QString &input, const ushort *actions, int from, int to) static inline void appendToUser(QString &appendTo, const QStringRef &value, QUrl::FormattingOptions options, const ushort *actions) { - if (options == QUrl::PrettyDecoded) { + // Test ComponentFormattingOptions, ignore FormattingOptions. + if ((options & 0xFFFF0000) == QUrl::PrettyDecoded) { appendTo += value; return; } @@ -3321,9 +3322,10 @@ QString QUrl::toString(FormattingOptions options) const // also catches isEmpty() return url; } - if (options == QUrl::FullyDecoded) { + if ((options & QUrl::FullyDecoded) == QUrl::FullyDecoded) { 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: @@ -3336,7 +3338,7 @@ QString QUrl::toString(FormattingOptions options) const && (!d->hasQuery() || options.testFlag(QUrl::RemoveQuery)) && (!d->hasFragment() || options.testFlag(QUrl::RemoveFragment)) && isLocalFile()) { - url = d->toLocalFile(options); + url = d->toLocalFile(options | QUrl::FullyDecoded); return url; } diff --git a/src/corelib/io/qurlrecode.cpp b/src/corelib/io/qurlrecode.cpp index 35ede8d078..3b2ef4a73d 100644 --- a/src/corelib/io/qurlrecode.cpp +++ b/src/corelib/io/qurlrecode.cpp @@ -672,7 +672,7 @@ qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end, QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications) { uchar actionTable[sizeof defaultActionTable]; - if (encoding == QUrl::FullyDecoded) { + if ((encoding & QUrl::FullyDecoded) == QUrl::FullyDecoded) { return decode(appendTo, reinterpret_cast<const ushort *>(begin), reinterpret_cast<const ushort *>(end)); } diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index ef4325d2ea..a3d6195895 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -70,6 +70,8 @@ private slots: void toString_PreferLocalFile(); void toString_constructed_data(); void toString_constructed(); + void toDisplayString_PreferLocalFile_data(); + void toDisplayString_PreferLocalFile(); void toAndFromStringList_data(); void toAndFromStringList(); void isParentOf_data(); @@ -1210,6 +1212,32 @@ void tst_QUrl::toString_constructed() 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() { |