diff --git a/modules/util/path.go b/modules/util/path.go index 0883349a88e..5679fa3f595 100644 --- a/modules/util/path.go +++ b/modules/util/path.go @@ -360,7 +360,7 @@ func IsReadmeFileExtension(name string, ext ...string) (int, bool) { } } - if name[6] == '.' { + if len(name) > 6 && name[6] == '.' { return len(ext), true } diff --git a/modules/util/path_test.go b/modules/util/path_test.go index 74adc44a89c..cb38644479d 100644 --- a/modules/util/path_test.go +++ b/modules/util/path_test.go @@ -142,6 +142,10 @@ func TestMisc_IsReadmeFileName(t *testing.T) { assert.Equal(t, testCase.expected, ok) assert.Equal(t, testCase.idx, idx) } + + idx, ok := IsReadmeFileExtension("readme", ".md") + assert.False(t, ok) + assert.Zero(t, idx) } func TestCleanPath(t *testing.T) {