forked from tangled.org/core
this repo has no description

appview: state: verify if commit is a valid hash before fetching

Fixes a crash when viewing a single commit, and possibly appending something like `.patch` to the end of it. The `result` from the knotserver is nil and then leads to a nil pointer deref later.

Changed files
+7
appview
state
+7
appview/state/repo.go
···
"github.com/bluesky-social/indigo/atproto/syntax"
securejoin "github.com/cyphar/filepath-securejoin"
"github.com/go-chi/chi/v5"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview/auth"
"tangled.sh/tangled.sh/core/appview/db"
···
if !s.config.Dev {
protocol = "https"
}
resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/commit/%s", protocol, f.Knot, f.OwnerDid(), f.RepoName, ref))
if err != nil {
log.Println("failed to reach knotserver", err)
···
"github.com/bluesky-social/indigo/atproto/syntax"
securejoin "github.com/cyphar/filepath-securejoin"
"github.com/go-chi/chi/v5"
+
"github.com/go-git/go-git/v5/plumbing"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/appview/auth"
"tangled.sh/tangled.sh/core/appview/db"
···
if !s.config.Dev {
protocol = "https"
}
+
+
if !plumbing.IsHash(ref) {
+
s.pages.Error404(w)
+
return
+
}
+
resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/commit/%s", protocol, f.Knot, f.OwnerDid(), f.RepoName, ref))
if err != nil {
log.Println("failed to reach knotserver", err)