Git: Improve local file detection in GitRemote

* Make sure url has a proper size before accessing
  its elements
* Also check for valid drive letter before ':'

Change-Id: I958cbd492caa8a6ad4a5bf424277d8287f8cf0d4
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Andre Hartmann
2018-09-22 23:01:39 +02:00
committed by André Hartmann
parent 30bd144540
commit e79d68dab6

View File

@@ -3385,8 +3385,14 @@ GitRemote::GitRemote(const QString &url)
// Check for local remotes (refer to the root or relative path) // Check for local remotes (refer to the root or relative path)
// On Windows, local paths typically starts with <drive>: // On Windows, local paths typically starts with <drive>:
auto startsWithWindowsDrive = [](const QString &url) {
if (!HostOsInfo::isWindowsHost() || url.size() < 2)
return false;
const QChar drive = url.at(0).toLower();
return drive >= 'a' && drive <= 'z' && url.at(1) == ':';
};
if (url.startsWith("file://") || url.startsWith('/') || url.startsWith('.') if (url.startsWith("file://") || url.startsWith('/') || url.startsWith('.')
|| (HostOsInfo::isWindowsHost() && url[1] == ':')) { || startsWithWindowsDrive(url)) {
protocol = "file"; protocol = "file";
path = QDir::fromNativeSeparators(url.startsWith("file://") ? url.mid(7) : url); path = QDir::fromNativeSeparators(url.startsWith("file://") ? url.mid(7) : url);
isValid = QDir(path).exists() || QDir(path + ".git").exists(); isValid = QDir(path).exists() || QDir(path + ".git").exists();