mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-02 15:09:33 -05:00
Fix raw file visit
This commit is contained in:
parent
bcf6e82dd0
commit
30a2ff1af6
@ -823,13 +823,16 @@ func getRefName(ctx *Base, repo *Repository, pathType RepoRefType) string {
|
||||
// For legacy and API support only full commit sha
|
||||
parts := strings.Split(path, "/")
|
||||
|
||||
if len(parts) > 1 && len(parts[0]) == git.ObjectFormatFromName(repo.Repository.ObjectFormatName).FullLength() {
|
||||
repo.TreePath = strings.Join(parts[1:], "/")
|
||||
return parts[0]
|
||||
}
|
||||
if refName := getRefName(ctx, repo, RepoRefBlob); len(refName) > 0 {
|
||||
return refName
|
||||
if len(parts) > 1 {
|
||||
if len(parts[0]) == git.ObjectFormatFromName(repo.Repository.ObjectFormatName).FullLength() {
|
||||
repo.TreePath = strings.Join(parts[1:], "/")
|
||||
return parts[0]
|
||||
}
|
||||
if refName := getRefName(ctx, repo, RepoRefBlob); len(refName) > 0 {
|
||||
return refName
|
||||
}
|
||||
}
|
||||
|
||||
repo.TreePath = path
|
||||
return repo.Repository.DefaultBranch
|
||||
case RepoRefBranch:
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
||||
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
||||
34865bf344ac1b427da08fcb845a2eab4706067c
|
||||
|
@ -191,5 +191,19 @@ func TestAPIGetContentsRefFormats(t *testing.T) {
|
||||
raw, err = io.ReadAll(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, content, string(raw))
|
||||
|
||||
// Test with a filepath with 40 characters
|
||||
fileWith40c := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + "a_file_path_with_40_characters_for_tests"
|
||||
resp = MakeRequest(t, NewRequest(t, http.MethodGet, fileWith40c), http.StatusOK)
|
||||
raw, err = io.ReadAll(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "# test\n", string(raw))
|
||||
|
||||
// Test with a filepath with 40 characters and name is a commit SHA
|
||||
fileWith40c = setting.AppURL + "api/v1/repos/user2/repo1/raw/" + "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
||||
resp = MakeRequest(t, NewRequest(t, http.MethodGet, fileWith40c), http.StatusOK)
|
||||
raw, err = io.ReadAll(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "# 65f1bf27bc3bf70f64657658635e66094edbcb4d\n", string(raw))
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user