summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAapo Haapanen <ext-aapo.haapanen@nokia.com>2012-01-26 16:11:40 +0200
committerPasi Pentikäinen <ext-pasi.a.pentikainen@nokia.com>2012-02-03 10:35:55 +0100
commit07e2c3316b544c96e082acea774d089119ed7c5a (patch)
tree929dfc726c31b1a0a0c2e1549dacb48cc52af3a2
parent24fa03682480911288adacd94c2f0beef2f8dcb8 (diff)
downloadqt4-tools-07e2c3316b544c96e082acea774d089119ed7c5a.tar.gz
Change QUrl::toLocalFile to return path for relative urls
This change reverts the behaviour of QUrl::toLocalFile to the state it was before 4.8. After this change the function returns the path if the url is relative. Before this change an empty QString was returned. A relative url can refer to a local file, but that can't be determined from the url alone. Thus, it makes sense to return the path for such urls. Added documentation to explain that the function works like this to maintain backward compatability in 4.x, but the handling of relative URLs will change in 5.0. Task-number: QTBUG-19827 Change-Id: I8bb8f4603a5936c0359afc1b6ff98824fad6cbc9 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 182acb541a7b8ac0edca842fdc867751df723f50) Reviewed-by: Pasi Pentikäinen <ext-pasi.a.pentikainen@nokia.com>
-rw-r--r--src/corelib/io/qurl.cpp9
-rw-r--r--tests/auto/qurl/tst_qurl.cpp8
2 files changed, 13 insertions, 4 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 60a4ce3c8b..9c20bd825d 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -6153,12 +6153,19 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
returned value in the form found on SMB networks (for example,
"//servername/path/to/file.txt").
+ If this is a relative URL, in Qt 4.x this function returns the path to
+ maintain backward compatability. This will change from 5.0 onwards. Then
+ the path is returned only for URLs where the scheme is "file", and for
+ all other URLs an empty string is returned.
+
\sa fromLocalFile(), isLocalFile()
*/
QString QUrl::toLocalFile() const
{
+ if (!d) return QString();
+
// the call to isLocalFile() also ensures that we're parsed
- if (!isLocalFile())
+ if (!isLocalFile() && !d->scheme.isEmpty())
return QString();
QString tmp;
diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp
index 2fa193a432..5c1933e9ad 100644
--- a/tests/auto/qurl/tst_qurl.cpp
+++ b/tests/auto/qurl/tst_qurl.cpp
@@ -1774,10 +1774,12 @@ void tst_QUrl::toLocalFile_data()
QTest::newRow("data9") << QString::fromLatin1("file:////somehost/somedir/somefile") << QString::fromLatin1("//somehost/somedir/somefile");
QTest::newRow("data10") << QString::fromLatin1("FILE:/a.txt") << QString::fromLatin1("/a.txt");
+ // relative urls
+ QTest::newRow("relative0") << QString::fromLatin1("a.txt") << QString::fromLatin1("a.txt");
+ QTest::newRow("relative1") << QString::fromLatin1("/a.txt") << QString::fromLatin1("/a.txt");
+ QTest::newRow("relative2") << QString::fromLatin1("//a.txt") << QString::fromLatin1("//a.txt");
+
// and some that result in empty (i.e., not local)
- QTest::newRow("xdata0") << QString::fromLatin1("/a.txt") << QString();
- QTest::newRow("xdata1") << QString::fromLatin1("//a.txt") << QString();
- QTest::newRow("xdata2") << QString::fromLatin1("///a.txt") << QString();
QTest::newRow("xdata3") << QString::fromLatin1("foo:/a.txt") << QString();
QTest::newRow("xdata4") << QString::fromLatin1("foo://a.txt") << QString();
QTest::newRow("xdata5") << QString::fromLatin1("foo:///a.txt") << QString();