From c670c27f19b319395f46025c173ec869e0fed8ad Mon Sep 17 00:00:00 2001 From: Bryan Kneis Date: Tue, 7 Jan 2025 10:26:21 +0000 Subject: [PATCH 1/2] Check if URL contains basic auth in URL --- pkg/git/git.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/git/git.go b/pkg/git/git.go index 39f544f2b..094816658 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -58,8 +58,17 @@ func NormalizeRepository(str string) (string, string, string, string, string) { // resolve branch branch := "" if match := branchRegEx.FindStringSubmatch(str); match != nil { - str = match[1] - branch = match[2] + // Check if basic auth is used, if so concat the user info and URL + if strings.Contains(match[1], ":") { + str = match[1] + "@" + match[2] + if innerMatch := branchRegEx.FindStringSubmatch(str); innerMatch != nil { + str = innerMatch[1] + branch = innerMatch[2] + } + } else { + str = match[1] + branch = match[2] + } } // resolve commit hash From 4e19c86f5695b0d4afd278e9fe4cd036ba328960 Mon Sep 17 00:00:00 2001 From: Bryan Kneis Date: Tue, 7 Jan 2025 14:36:26 +0000 Subject: [PATCH 2/2] Update regex --- pkg/git/git.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/pkg/git/git.go b/pkg/git/git.go index 094816658..10b67d792 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -23,8 +23,8 @@ const ( // WARN: Make sure this matches the regex in /desktop/src/views/Workspaces/CreateWorkspace/CreateWorkspaceInput.tsx! var ( // Updated regex pattern to support SSH-style Git URLs - repoBaseRegEx = `((?:(?:https?|git|ssh|file):\/\/)?\/?(?:[^@\/\n]+@)?(?:[^:\/\n]+)(?:[:\/][^\/\n]+)+(?:\.git)?)` - branchRegEx = regexp.MustCompile(`^` + repoBaseRegEx + `@([a-zA-Z0-9\./\-\_]+)$`) + repoBaseRegEx = `((?:(?:https?|git|ssh|file):\/\/)?(?:[^:@\/\n]+(?::[^@\/\n]+)?@)?(?:[^:\/\n]+|(?:\/[^\/\n]+)+)(?:[:\/][^\/\n]+)+(?:\.git))` + branchRegEx = regexp.MustCompile(`^` + repoBaseRegEx + `(?:@([a-zA-Z0-9\./\-\_]+))?$`) commitRegEx = regexp.MustCompile(`^` + repoBaseRegEx + regexp.QuoteMeta(CommitDelimiter) + `([a-zA-Z0-9]+)$`) prReferenceRegEx = regexp.MustCompile(`^` + repoBaseRegEx + `@(` + PullRequestReference + `)$`) subPathRegEx = regexp.MustCompile(`^` + repoBaseRegEx + regexp.QuoteMeta(SubPathDelimiter) + `([a-zA-Z0-9\./\-\_]+)$`) @@ -58,17 +58,8 @@ func NormalizeRepository(str string) (string, string, string, string, string) { // resolve branch branch := "" if match := branchRegEx.FindStringSubmatch(str); match != nil { - // Check if basic auth is used, if so concat the user info and URL - if strings.Contains(match[1], ":") { - str = match[1] + "@" + match[2] - if innerMatch := branchRegEx.FindStringSubmatch(str); innerMatch != nil { - str = innerMatch[1] - branch = innerMatch[2] - } - } else { - str = match[1] - branch = match[2] - } + str = match[1] + branch = match[2] } // resolve commit hash