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:
parent
5abd72d42a
commit
16482c507b
@ -59,6 +59,14 @@ namespace
|
|||||||
});
|
});
|
||||||
return hasSeparator ? QDir::cleanPath(path) : path;
|
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)
|
Path::Path(const QString &pathStr)
|
||||||
@ -80,8 +88,13 @@ bool Path::isValid() const
|
|||||||
|
|
||||||
// https://stackoverflow.com/a/31976060
|
// https://stackoverflow.com/a/31976060
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
|
QStringView view = m_pathStr;
|
||||||
|
if (hasDriveLetter(view))
|
||||||
|
view = view.mid(3);
|
||||||
|
|
||||||
// \\37 is using base-8 number system
|
// \\37 is using base-8 number system
|
||||||
const QRegularExpression regex {u"[\\0-\\37:?\"*<>|]"_qs};
|
const QRegularExpression regex {u"[\\0-\\37:?\"*<>|]"_qs};
|
||||||
|
return !regex.match(view).hasMatch();
|
||||||
#elif defined(Q_OS_MACOS)
|
#elif defined(Q_OS_MACOS)
|
||||||
const QRegularExpression regex {u"[\\0:]"_qs};
|
const QRegularExpression regex {u"[\\0:]"_qs};
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user