From e26483c106cd1408b768f18f5d0edfd83c78f5bf Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Wed, 27 Aug 2014 16:25:40 +0200 Subject: [PATCH] Fix URL handling in PLS parser. Make sure relative paths are resolved to a full path. Task-number: QTBUG-40515 Change-Id: Ideb83fc3a3c4a74c84917a22e3c30162d7b6158a Reviewed-by: Christian Stromme --- src/multimedia/playback/playlistfileparser.cpp | 51 +++++++++++----------- tests/auto/unit/qmediaplaylist/testdata/test.pls | 19 +++++++- .../unit/qmediaplaylist/tst_qmediaplaylist.cpp | 14 +++++- 3 files changed, 57 insertions(+), 27 deletions(-) diff --git a/src/multimedia/playback/playlistfileparser.cpp b/src/multimedia/playback/playlistfileparser.cpp index 1254d61..97c551c 100644 --- a/src/multimedia/playback/playlistfileparser.cpp +++ b/src/multimedia/playback/playlistfileparser.cpp @@ -59,6 +59,30 @@ public: virtual void parseLine(int lineIndex, const QString& line, const QUrl& root) = 0; +protected: + QUrl expandToFullPath(const QUrl &root, const QString &line) + { + // On Linux, backslashes are not converted to forward slashes :/ + if (line.startsWith(QLatin1String("//")) || line.startsWith(QLatin1String("\\\\"))) { + // Network share paths are not resolved + return QUrl::fromLocalFile(line); + } + + QUrl url(line); + if (url.scheme().isEmpty()) { + // Resolve it relative to root + if (root.isLocalFile()) + return root.resolved(QUrl::fromLocalFile(line)); + else + return root.resolved(url); + } else if (url.scheme().length() == 1) { + // Assume it's a drive letter for a Windows path + url = QUrl::fromLocalFile(line); + } + + return url; + } + Q_SIGNALS: void newItem(const QVariant& content); void finished(); @@ -146,29 +170,6 @@ public: return -1; } - QUrl expandToFullPath(const QUrl& root, const QString& line) - { - // On Linux, backslashes are not converted to forward slashes :/ - if (line.startsWith(QLatin1String("//")) || line.startsWith(QLatin1String("\\\\"))) { - // Network share paths are not resolved - return QUrl::fromLocalFile(line); - } - - QUrl url(line); - if (url.scheme().isEmpty()) { - // Resolve it relative to root - if (root.isLocalFile()) - return root.resolved(QUrl::fromLocalFile(line)); - else - return root.resolved(url); - } else if (url.scheme().length() == 1) { - // Assume it's a drive letter for a Windows path - url = QUrl::fromLocalFile(line); - } - - return url; - } - private: bool m_extendedFormat; QVariantMap m_extraInfo; @@ -249,7 +250,7 @@ Version=2 m_readFlags |= int(flag); } - void parseLine(int lineIndex, const QString& line, const QUrl&) + void parseLine(int lineIndex, const QString &line, const QUrl &root) { switch (m_state) { case Header: @@ -260,7 +261,7 @@ Version=2 break; case Track: if (!containsFlag(FileRead) && line.startsWith(m_fileName)) { - m_item[QLatin1String("url")] = getValue(lineIndex, line); + m_item[QLatin1String("url")] = expandToFullPath(root, getValue(lineIndex, line)); setFlag(FileRead); } else if (!containsFlag(TitleRead) && line.startsWith(m_titleName)) { m_item[QMediaMetaData::Title] = getValue(lineIndex, line); diff --git a/tests/auto/unit/qmediaplaylist/testdata/test.pls b/tests/auto/unit/qmediaplaylist/testdata/test.pls index 1b66c3a..18832b1 100644 --- a/tests/auto/unit/qmediaplaylist/testdata/test.pls +++ b/tests/auto/unit/qmediaplaylist/testdata/test.pls @@ -6,5 +6,22 @@ Length1=-1 File2= http://test.host/path Title2=Second Length2=-1 +File3=testfile +Title3=Third +Length3=-1 -NumberOfEntries=2 + + +File4=testdir/testfile +Title4=Fourth +Length4=-1 +File5=/testdir/testfile +Title5=Fifth +Length5=-1 +File6=file://path/name#suffix +Title6=Sixth +Length6=-1 +File7=testfile2#suffix +Title7=Seventh +Length7=-1 +NumberOfEntries=7 diff --git a/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp b/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp index 63b84b5..748bcd3 100644 --- a/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp +++ b/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp @@ -488,9 +488,21 @@ void tst_QMediaPlaylist::loadPLSFile() QTRY_VERIFY(!loadSpy.isEmpty()); QVERIFY(loadFailedSpy.isEmpty()); QCOMPARE(playlist.error(), QMediaPlaylist::NoError); - QCOMPARE(playlist.mediaCount(), 2); + QCOMPARE(playlist.mediaCount(), 7); + QCOMPARE(playlist.media(0).canonicalUrl(), QUrl(QLatin1String("http://test.host/path"))); QCOMPARE(playlist.media(1).canonicalUrl(), QUrl(QLatin1String("http://test.host/path"))); + testFileName = QFINDTESTDATA("testdata/testfile"); + QCOMPARE(playlist.media(2).canonicalUrl(), + QUrl::fromLocalFile(testFileName)); + testFileName = QFINDTESTDATA("testdata"); + QCOMPARE(playlist.media(3).canonicalUrl(), + QUrl::fromLocalFile(testFileName + "/testdir/testfile")); + QCOMPARE(playlist.media(4).canonicalUrl(), QUrl(QLatin1String("file:///testdir/testfile"))); + QCOMPARE(playlist.media(5).canonicalUrl(), QUrl(QLatin1String("file://path/name#suffix"))); + //ensure #2 suffix is not stripped from path + testFileName = QFINDTESTDATA("testdata/testfile2#suffix"); + QCOMPARE(playlist.media(6).canonicalUrl(), QUrl::fromLocalFile(testFileName)); // Try to load a totem-pl generated playlist loadSpy.clear(); -- 2.7.4