diff options
-rw-r--r-- | app/assets/javascripts/repository/utils/readme.js | 2 | ||||
-rw-r--r-- | changelogs/unreleased/25343-show-readme-txt.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/file_detector.rb | 2 | ||||
-rw-r--r-- | spec/frontend/repository/utils/readme_spec.js | 6 | ||||
-rw-r--r-- | spec/helpers/markup_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/file_detector_spec.rb | 23 |
6 files changed, 29 insertions, 11 deletions
diff --git a/app/assets/javascripts/repository/utils/readme.js b/app/assets/javascripts/repository/utils/readme.js index ef4162f4463..5b62271b02e 100644 --- a/app/assets/javascripts/repository/utils/readme.js +++ b/app/assets/javascripts/repository/utils/readme.js @@ -24,7 +24,7 @@ const isRichReadme = file => { }; const isPlainReadme = file => { - const re = new RegExp(`^(${FILENAMES.join('|')})$`, 'i'); + const re = new RegExp(`^(${FILENAMES.join('|')})(\\.txt)?$`, 'i'); return re.test(file.name); }; diff --git a/changelogs/unreleased/25343-show-readme-txt.yml b/changelogs/unreleased/25343-show-readme-txt.yml new file mode 100644 index 00000000000..d4b450beb0a --- /dev/null +++ b/changelogs/unreleased/25343-show-readme-txt.yml @@ -0,0 +1,5 @@ +--- +title: Fix README.txt not showing up on a project page +merge_request: 21763 +author: Alexander Oleynikov +type: fixed diff --git a/lib/gitlab/file_detector.rb b/lib/gitlab/file_detector.rb index 234c834a83a..305fbeecce1 100644 --- a/lib/gitlab/file_detector.rb +++ b/lib/gitlab/file_detector.rb @@ -8,7 +8,7 @@ module Gitlab module FileDetector PATTERNS = { # Project files - readme: /\A(#{Regexp.union(*Gitlab::MarkupHelper::PLAIN_FILENAMES).source})(\.(#{Regexp.union(*Gitlab::MarkupHelper::EXTENSIONS).source}))?\z/i, + readme: /\A(#{Regexp.union(*Gitlab::MarkupHelper::PLAIN_FILENAMES).source})(\.(txt|#{Regexp.union(*Gitlab::MarkupHelper::EXTENSIONS).source}))?\z/i, changelog: %r{\A(changelog|history|changes|news)[^/]*\z}i, license: %r{\A((un)?licen[sc]e|copying)(\.[^/]+)?\z}i, contributing: %r{\Acontributing[^/]*\z}i, diff --git a/spec/frontend/repository/utils/readme_spec.js b/spec/frontend/repository/utils/readme_spec.js index 1b275de86c3..985d947a0af 100644 --- a/spec/frontend/repository/utils/readme_spec.js +++ b/spec/frontend/repository/utils/readme_spec.js @@ -31,6 +31,12 @@ describe('readmeFile', () => { }); }); + it('recognizes Readme.txt as a plain text README', () => { + expect(readmeFile([{ name: 'Readme.txt' }])).toEqual({ + name: 'Readme.txt', + }); + }); + it('returns undefined when there are no appropriate files', () => { expect(readmeFile([{ name: 'index.js' }, { name: 'md.README' }])).toBe(undefined); expect(readmeFile([])).toBe(undefined); diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index fce0b5bd7e3..66d461a871c 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -410,7 +410,7 @@ describe MarkupHelper do end context 'when file has an unknown type' do - let(:file_name) { 'foo' } + let(:file_name) { 'foo.tex' } it 'returns html (rendered by Gitlab::OtherMarkup)' do expected_html = 'Noël' diff --git a/spec/lib/gitlab/file_detector_spec.rb b/spec/lib/gitlab/file_detector_spec.rb index 23f7deba7f7..3972bd24e80 100644 --- a/spec/lib/gitlab/file_detector_spec.rb +++ b/spec/lib/gitlab/file_detector_spec.rb @@ -16,23 +16,30 @@ describe Gitlab::FileDetector do end describe '.type_of' do - it 'returns the type of a README file' do - filenames = Gitlab::MarkupHelper::PLAIN_FILENAMES + Gitlab::MarkupHelper::PLAIN_FILENAMES.map(&:upcase) - extensions = Gitlab::MarkupHelper::EXTENSIONS + Gitlab::MarkupHelper::EXTENSIONS.map(&:upcase) + it 'returns the type of a README without extension' do + expect(described_class.type_of('README')).to eq(:readme) + expect(described_class.type_of('INDEX')).to eq(:readme) + end - filenames.each do |filename| - expect(described_class.type_of(filename)).to eq(:readme) + it 'returns the type of a README file with a recognized extension' do + extensions = ['txt', *Gitlab::MarkupHelper::EXTENSIONS] - extensions.each do |extname| - expect(described_class.type_of("#{filename}.#{extname}")).to eq(:readme) + extensions.each do |ext| + %w(index readme).each do |file| + expect(described_class.type_of("#{file}.#{ext}")).to eq(:readme) end end end - it 'returns nil for a README.rb file' do + it 'returns nil for a README with unrecognized extension' do expect(described_class.type_of('README.rb')).to be_nil end + it 'is case insensitive' do + expect(described_class.type_of('ReadMe')).to eq(:readme) + expect(described_class.type_of('index.TXT')).to eq(:readme) + end + it 'returns nil for a README file in a directory' do expect(described_class.type_of('foo/README.md')).to be_nil end |