Only do QUrl toEncoded() if url is valid

This commit is contained in:
Jonas Kvinge
2019-03-10 21:09:05 +01:00
parent c41311bf76
commit 242137a50c
2 changed files with 11 additions and 6 deletions

View File

@@ -1059,12 +1059,16 @@ void Song::BindToQuery(QSqlQuery *query) const {
query->bindValue(":source", d->source_); query->bindValue(":source", d->source_);
query->bindValue(":directory_id", notnullintval(d->directory_id_)); query->bindValue(":directory_id", notnullintval(d->directory_id_));
if (Application::kIsPortable && Utilities::UrlOnSameDriveAsStrawberry(d->url_)) { QString url;
query->bindValue(":filename", Utilities::GetRelativePathToStrawberryBin(d->url_).toEncoded()); if (d->url_.isValid()) {
} if (Application::kIsPortable && Utilities::UrlOnSameDriveAsStrawberry(d->url_)) {
else { url = Utilities::GetRelativePathToStrawberryBin(d->url_).toEncoded();
query->bindValue(":filename", d->url_.toEncoded()); }
else {
url = d->url_.toEncoded();
}
} }
query->bindValue(":filename", url);
query->bindValue(":filetype", d->filetype_); query->bindValue(":filetype", d->filetype_);
query->bindValue(":filesize", notnullintval(d->filesize_)); query->bindValue(":filesize", notnullintval(d->filesize_));

View File

@@ -644,7 +644,7 @@ bool IsLaptop() {
bool UrlOnSameDriveAsStrawberry(const QUrl &url) { bool UrlOnSameDriveAsStrawberry(const QUrl &url) {
if (url.scheme() != "file") return false; if (!url.isValid() || url.scheme() != "file" || url.toLocalFile().isEmpty()) return false;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QUrl appUrl = QUrl::fromLocalFile(QCoreApplication::applicationDirPath()); QUrl appUrl = QUrl::fromLocalFile(QCoreApplication::applicationDirPath());
@@ -660,6 +660,7 @@ bool UrlOnSameDriveAsStrawberry(const QUrl &url) {
} }
QUrl GetRelativePathToStrawberryBin(const QUrl &url) { QUrl GetRelativePathToStrawberryBin(const QUrl &url) {
if (!url.isValid()) return QUrl();
QDir appPath(QCoreApplication::applicationDirPath()); QDir appPath(QCoreApplication::applicationDirPath());
return QUrl::fromLocalFile(appPath.relativeFilePath(url.toLocalFile())); return QUrl::fromLocalFile(appPath.relativeFilePath(url.toLocalFile()));
} }