Commit 6ac06e95 authored by Steve Azzopardi's avatar Steve Azzopardi

Merge branch...

Merge branch '54011-all-files-named-index-have-their-content-rendered-as-if-they-were-text-files' into 'master'

Resolve "All files named `index.*` have their content rendered as if they were text files"

Closes #54011

See merge request gitlab-org/gitlab-ce!23063
parents 348dd42d a4ae5411
......@@ -8,7 +8,7 @@ module Gitlab
module FileDetector
PATTERNS = {
# Project files
readme: %r{\A(readme|index)[^/]*\z}i,
readme: /\A(#{Regexp.union(*Gitlab::MarkupHelper::PLAIN_FILENAMES).source})(\.(#{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,
......
......@@ -15,14 +15,22 @@ describe Gitlab::FileDetector do
describe '.type_of' do
it 'returns the type of a README file' do
%w[README readme INDEX index].each do |filename|
filenames = Gitlab::MarkupHelper::PLAIN_FILENAMES + Gitlab::MarkupHelper::PLAIN_FILENAMES.map(&:upcase)
extensions = Gitlab::MarkupHelper::EXTENSIONS + Gitlab::MarkupHelper::EXTENSIONS.map(&:upcase)
filenames.each do |filename|
expect(described_class.type_of(filename)).to eq(:readme)
%w[.md .adoc .rst].each do |extname|
expect(described_class.type_of(filename + extname)).to eq(:readme)
extensions.each do |extname|
expect(described_class.type_of("#{filename}.#{extname}")).to eq(:readme)
end
end
end
it 'returns nil for a README.rb file' do
expect(described_class.type_of('README.rb')).to be_nil
end
it 'returns nil for a README file in a directory' do
expect(described_class.type_of('foo/README.md')).to be_nil
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