diff --git a/internal/install/submodule.go b/internal/install/submodule.go index 9c6414948..355b2b7ed 100644 --- a/internal/install/submodule.go +++ b/internal/install/submodule.go @@ -32,16 +32,17 @@ func (l gitlink) String() string { // accepts any text there, so this fails closed on the raw string: everything // before the last "@" goes, keeping only a well-formed "scheme://" prefix. func displayURL(raw string) string { + // Userinfo first: a "?" or "#" inside it must not hide the "@". + if at := strings.LastIndex(raw, "@"); at >= 0 { + if scheme, _, ok := strings.Cut(raw[:at], "://"); ok { + raw = scheme + "://" + raw[at+1:] + } else { + raw = raw[at+1:] + } + } raw, _, _ = strings.Cut(raw, "#") raw, _, _ = strings.Cut(raw, "?") - at := strings.LastIndex(raw, "@") - if at < 0 { - return raw - } - if scheme, _, ok := strings.Cut(raw[:at], "://"); ok { - return scheme + "://" + raw[at+1:] - } - return raw[at+1:] + return raw } // repoGitlinks lists the submodules recorded in HEAD of repoPath. extraEnv diff --git a/internal/install/submodule_test.go b/internal/install/submodule_test.go index 328031bd2..73c6a7e40 100644 --- a/internal/install/submodule_test.go +++ b/internal/install/submodule_test.go @@ -155,6 +155,8 @@ func TestGitlinkString_HidesURLCredentials(t *testing.T) { "s3cret@example.com:org/up.git": "example.com:org/up.git", "https:/user:s3cret@example.com/org/up.git": "example.com/org/up.git", "//user:s3cret@example.com/org/up.git": "example.com/org/up.git", + "https://user:s3cret?x@example.com/org/up.git": "https://example.com/org/up.git", + "https://user:s3cret#x@example.com/org/up.git": "https://example.com/org/up.git", } { got := gitlink{Path: "vendor/up", Commit: "abc", URL: raw}.String() if strings.Contains(got, "s3cret") || !strings.Contains(got, want) {