summaryrefslogtreecommitdiff
path: root/src/plugins/git/gitclient.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2019-07-23 16:15:57 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2019-07-26 10:41:03 +0000
commitdf8ef72aec830d253beef32ee4d9b962afc3346e (patch)
tree24809b9298550450564688dd75bf77481f4c8971 /src/plugins/git/gitclient.cpp
parent00bdb007ee7923f79b60c68fb891740af2f598a1 (diff)
downloadqt-creator-df8ef72aec830d253beef32ee4d9b962afc3346e.tar.gz
Wizards: Do some input validation on repository URLs
Fixes: QTCREATORBUG-18935 Change-Id: Ie2103cbe2899ea23caaedd4a6350c78b5f380ab9 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: André Hartmann <aha_1980@gmx.de>
Diffstat (limited to 'src/plugins/git/gitclient.cpp')
-rw-r--r--src/plugins/git/gitclient.cpp38
1 files changed, 2 insertions, 36 deletions
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index 44f4d35f88..8c84c61354 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -3458,44 +3458,10 @@ void GitClient::StashInfo::end()
m_stashResult = NotStashed;
}
-// GitRemote
-
-GitRemote::GitRemote(const QString &url)
+GitRemote::GitRemote(const QString &location) : Core::IVersionControl::RepoUrl(location)
{
- static const QRegularExpression remotePattern(
- "^(?:(?<protocol>[^:]+)://)?(?:(?<user>[^@]+)@)?(?<host>[^:/]+)"
- "(?::(?<port>\\d+))?:?(?<path>.*)$");
-
- if (url.isEmpty())
- return;
-
- // Check for local remotes (refer to the root or relative path)
- // 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('.')
- || startsWithWindowsDrive(url)) {
- protocol = "file";
- path = QDir::fromNativeSeparators(url.startsWith("file://") ? url.mid(7) : url);
+ if (isValid && protocol == "file")
isValid = QDir(path).exists() || QDir(path + ".git").exists();
- return;
- }
-
- const QRegularExpressionMatch match = remotePattern.match(url);
- if (!match.hasMatch())
- return;
-
- bool ok = false;
- protocol = match.captured("protocol");
- userName = match.captured("user");
- host = match.captured("host");
- port = match.captured("port").toUShort(&ok);
- path = match.captured("path");
- isValid = ok || match.captured("port").isEmpty();
}
} // namespace Internal