diff options
author | Khaled Hamed <khaled.hamedt@gmail.com> | 2019-01-14 21:15:06 +0200 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2019-01-14 14:15:06 -0500 |
commit | bd759652965078c0cd5b948c94345ce5b73fd0d1 (patch) | |
tree | 9a3ecf0f7aaa13db0b87169c3dad077647e564b0 /modules | |
parent | 6868378673f5bb21eac54719d719557b32448db6 (diff) | |
download | gitea-bd759652965078c0cd5b948c94345ce5b73fd0d1.tar.gz gitea-bd759652965078c0cd5b948c94345ce5b73fd0d1.zip |
Prioritize "readme.md" (#5691)
* prioritize readme.md
* Improve IsReadmeFile
* Add more tests
Diffstat (limited to 'modules')
-rw-r--r-- | modules/markup/markup.go | 9 | ||||
-rw-r--r-- | modules/markup/markup_test.go | 22 |
2 files changed, 29 insertions, 2 deletions
diff --git a/modules/markup/markup.go b/modules/markup/markup.go index d17270fb01..c506007723 100644 --- a/modules/markup/markup.go +++ b/modules/markup/markup.go @@ -111,9 +111,14 @@ func IsMarkupFile(name, markup string) bool { } // IsReadmeFile reports whether name looks like a README file -// based on its name. -func IsReadmeFile(name string) bool { +// based on its name. If an extension is provided, it will strictly +// match that extension. +// Note that the '.' should be provided in ext, e.g ".md" +func IsReadmeFile(name string, ext ...string) bool { name = strings.ToLower(name) + if len(ext) > 0 { + return name == "readme"+ext[0] + } if len(name) < 6 { return false } else if len(name) == 6 { diff --git a/modules/markup/markup_test.go b/modules/markup/markup_test.go index b0ebfae57d..118fa2632b 100644 --- a/modules/markup/markup_test.go +++ b/modules/markup/markup_test.go @@ -19,6 +19,7 @@ func TestMisc_IsReadmeFile(t *testing.T) { "README", "readME.mdown", "README.md", + "readme.i18n.md", } falseTestCases := []string{ "test.md", @@ -37,4 +38,25 @@ func TestMisc_IsReadmeFile(t *testing.T) { for _, testCase := range falseTestCases { assert.False(t, IsReadmeFile(testCase)) } + + trueTestCasesStrict := [][]string{ + {"readme", ""}, + {"readme.md", ".md"}, + {"readme.txt", ".txt"}, + } + falseTestCasesStrict := [][]string{ + {"readme", ".md"}, + {"readme.md", ""}, + {"readme.md", ".txt"}, + {"readme.md", "md"}, + {"readmee.md", ".md"}, + {"readme.i18n.md", ".md"}, + } + + for _, testCase := range trueTestCasesStrict { + assert.True(t, IsReadmeFile(testCase[0], testCase[1])) + } + for _, testCase := range falseTestCasesStrict { + assert.False(t, IsReadmeFile(testCase[0], testCase[1])) + } } |