mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-07 05:31:25 -07:00
Fix drive letter validness check
This commit is contained in:
parent
5abd72d42a
commit
16482c507b
1 changed files with 13 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue