Commit 035fd458 authored by Thong Kuah's avatar Thong Kuah

Merge branch '25343-show-readme-txt' into 'master'

Show READMEs with .txt extension

Closes #25343

See merge request gitlab-org/gitlab!21763
parents f8718916 9ea9d7ac
...@@ -24,7 +24,7 @@ const isRichReadme = file => { ...@@ -24,7 +24,7 @@ const isRichReadme = file => {
}; };
const isPlainReadme = file => { const isPlainReadme = file => {
const re = new RegExp(`^(${FILENAMES.join('|')})$`, 'i'); const re = new RegExp(`^(${FILENAMES.join('|')})(\\.txt)?$`, 'i');
return re.test(file.name); return re.test(file.name);
}; };
......
---
title: Fix README.txt not showing up on a project page
merge_request: 21763
author: Alexander Oleynikov
type: fixed
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
module FileDetector module FileDetector
PATTERNS = { PATTERNS = {
# Project files # 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, changelog: %r{\A(changelog|history|changes|news)[^/]*\z}i,
license: %r{\A((un)?licen[sc]e|copying)(\.[^/]+)?\z}i, license: %r{\A((un)?licen[sc]e|copying)(\.[^/]+)?\z}i,
contributing: %r{\Acontributing[^/]*\z}i, contributing: %r{\Acontributing[^/]*\z}i,
......
...@@ -31,6 +31,12 @@ describe('readmeFile', () => { ...@@ -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', () => { it('returns undefined when there are no appropriate files', () => {
expect(readmeFile([{ name: 'index.js' }, { name: 'md.README' }])).toBe(undefined); expect(readmeFile([{ name: 'index.js' }, { name: 'md.README' }])).toBe(undefined);
expect(readmeFile([])).toBe(undefined); expect(readmeFile([])).toBe(undefined);
......
...@@ -410,7 +410,7 @@ describe MarkupHelper do ...@@ -410,7 +410,7 @@ describe MarkupHelper do
end end
context 'when file has an unknown type' do 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 it 'returns html (rendered by Gitlab::OtherMarkup)' do
expected_html = 'Noël' expected_html = 'Noël'
......
...@@ -16,23 +16,30 @@ describe Gitlab::FileDetector do ...@@ -16,23 +16,30 @@ describe Gitlab::FileDetector do
end end
describe '.type_of' do describe '.type_of' do
it 'returns the type of a README file' do it 'returns the type of a README without extension' do
filenames = Gitlab::MarkupHelper::PLAIN_FILENAMES + Gitlab::MarkupHelper::PLAIN_FILENAMES.map(&:upcase) expect(described_class.type_of('README')).to eq(:readme)
extensions = Gitlab::MarkupHelper::EXTENSIONS + Gitlab::MarkupHelper::EXTENSIONS.map(&:upcase) expect(described_class.type_of('INDEX')).to eq(:readme)
end
filenames.each do |filename| it 'returns the type of a README file with a recognized extension' do
expect(described_class.type_of(filename)).to eq(:readme) extensions = ['txt', *Gitlab::MarkupHelper::EXTENSIONS]
extensions.each do |extname| extensions.each do |ext|
expect(described_class.type_of("#{filename}.#{extname}")).to eq(:readme) %w(index readme).each do |file|
expect(described_class.type_of("#{file}.#{ext}")).to eq(:readme)
end end
end 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 expect(described_class.type_of('README.rb')).to be_nil
end 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 it 'returns nil for a README file in a directory' do
expect(described_class.type_of('foo/README.md')).to be_nil expect(described_class.type_of('foo/README.md')).to be_nil
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment