mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix(install): strip submodule URL userinfo before query and fragment
A ? or # inside the userinfo used to cut away the @ before it was found, leaving the credential in place.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user