fix: Fix the panic when ssh remote lfs endpoint parsing failure (#38026) (#38158)

Fix #38016
Backport #38026
This commit is contained in:
Lunny Xiao
2026-06-18 11:34:58 +03:00
committed by GitHub
parent 6fb96fcfdf
commit 0b9623e188
7 changed files with 74 additions and 12 deletions
+13 -1
View File
@@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"
giturl "code.gitea.io/gitea/modules/git/url"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
)
@@ -44,15 +45,20 @@ func endpointFromCloneURL(rawurl string) *url.URL {
}
func endpointFromURL(rawurl string) *url.URL {
if rawurl == "" {
return nil
}
if strings.HasPrefix(rawurl, "/") {
return endpointFromLocalPath(rawurl)
}
u, err := url.Parse(rawurl)
gitURL, err := giturl.ParseGitURL(rawurl)
if err != nil {
log.Error("lfs.endpointFromUrl: %v", err)
return nil
}
u := gitURL.URL
switch u.Scheme {
case "http", "https":
@@ -60,6 +66,12 @@ func endpointFromURL(rawurl string) *url.URL {
case "git":
u.Scheme = "https"
return u
case "ssh", "git+ssh":
u.Scheme = "https" // is it possible http?
u.Host = u.Hostname() // remove ssh port if any
u.Path = "/" + strings.TrimPrefix(u.Path, "/")
u.User = nil
return u
case "file":
return u
default: