1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-10 14:57:52 +00:00

Fix drive letter validness check

This commit is contained in:
Chocobo1 2022-08-12 18:04:51 +08:00
parent 5abd72d42a
commit 16482c507b
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C

View File

@ -59,6 +59,14 @@ namespace
});
return hasSeparator ? QDir::cleanPath(path) : path;
}
#ifdef Q_OS_WIN
bool hasDriveLetter(const QStringView path)
{
const QRegularExpression driveLetterRegex {u"^[A-Za-z]:/"_qs};
return driveLetterRegex.match(path).hasMatch();
}
#endif
}
Path::Path(const QString &pathStr)
@ -80,8 +88,13 @@ bool Path::isValid() const
// https://stackoverflow.com/a/31976060
#if defined(Q_OS_WIN)
QStringView view = m_pathStr;
if (hasDriveLetter(view))
view = view.mid(3);
// \\37 is using base-8 number system
const QRegularExpression regex {u"[\\0-\\37:?\"*<>|]"_qs};
return !regex.match(view).hasMatch();
#elif defined(Q_OS_MACOS)
const QRegularExpression regex {u"[\\0:]"_qs};
#else