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 <christian.stromme@digia.com>
This commit is contained in:
Yoann Lopes
2014-08-27 16:25:40 +02:00
parent 973ae5e0f6
commit e26483c106
3 changed files with 57 additions and 27 deletions

View File

@@ -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);