diff --git a/modules/base/natural_sort.go b/modules/base/natural_sort.go index e920177f8..5b5febb90 100644 --- a/modules/base/natural_sort.go +++ b/modules/base/natural_sort.go @@ -5,11 +5,13 @@ package base import ( "math/big" + "strings" "unicode/utf8" ) // NaturalSortLess compares two strings so that they could be sorted in natural order func NaturalSortLess(s1, s2 string) bool { + s1, s2 = strings.ToLower(s1), strings.ToLower(s2) var i1, i2 int for { rune1, j1, end1 := getNextRune(s1, i1) diff --git a/modules/base/natural_sort_test.go b/modules/base/natural_sort_test.go index 91e864ad2..7378d9a64 100644 --- a/modules/base/natural_sort_test.go +++ b/modules/base/natural_sort_test.go @@ -20,4 +20,10 @@ func TestNaturalSortLess(t *testing.T) { test("a-1-a", "a-1-b", true) test("2", "12", true) test("a", "ab", true) + + // Test for case insensitive. + test("A", "ab", true) + test("B", "ab", false) + test("a", "AB", true) + test("b", "AB", false) } diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index b62297e0e..03124ecaf 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -6,6 +6,7 @@ package integration import ( "fmt" "net/http" + "net/url" "path" "strings" "testing" @@ -15,11 +16,13 @@ import ( repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/translation" repo_service "code.gitea.io/gitea/services/repository" + files_service "code.gitea.io/gitea/services/repository/files" "code.gitea.io/gitea/tests" "github.com/PuerkitoBio/goquery" @@ -899,3 +902,62 @@ func TestRepoHomeViewRedirect(t *testing.T) { assert.Equal(t, "Wiki", txt) }) } + +func TestRepoFilesList(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + + // create the repo + repo, _, f := CreateDeclarativeRepo(t, user2, "", + []unit_model.Type{unit_model.TypeCode}, nil, + []*files_service.ChangeRepoFile{ + { + Operation: "create", + TreePath: "zEta", + ContentReader: strings.NewReader("zeta"), + }, + { + Operation: "create", + TreePath: "licensa", + ContentReader: strings.NewReader("licensa"), + }, + { + Operation: "create", + TreePath: "licensz", + ContentReader: strings.NewReader("licensz"), + }, + { + Operation: "create", + TreePath: "delta", + ContentReader: strings.NewReader("delta"), + }, + { + Operation: "create", + TreePath: "Charlie/aa.txt", + ContentReader: strings.NewReader("charlie"), + }, + { + Operation: "create", + TreePath: "Beta", + ContentReader: strings.NewReader("beta"), + }, + { + Operation: "create", + TreePath: "alpha", + ContentReader: strings.NewReader("alpha"), + }, + }, + ) + defer f() + + req := NewRequest(t, "GET", "/"+repo.FullName()) + resp := MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + filesList := htmlDoc.Find("#repo-files-table tbody tr").Map(func(_ int, s *goquery.Selection) string { + return s.AttrOr("data-entryname", "") + }) + + assert.EqualValues(t, []string{"Charlie", "alpha", "Beta", "delta", "licensa", "LICENSE", "licensz", "README.md", "zEta"}, filesList) + }) +}