Commit 548cfd8b authored by Nick Thomas's avatar Nick Thomas

Default to generating blob links for missing paths

parent 7ee66c95
---
title: Default to generating blob links for missing paths
merge_request: 26817
author:
type: fixed
......@@ -131,7 +131,7 @@ module Banzai
path = cleaned_file_path(uri)
nested_path = relative_file_path(uri)
file_exists?(nested_path) ? nested_path : path
path_exists?(nested_path) ? nested_path : path
end
def cleaned_file_path(uri)
......@@ -190,12 +190,12 @@ module Banzai
parts.push(path).join('/')
end
def file_exists?(path)
path.present? && uri_type(path).present?
def path_exists?(path)
path.present? && @uri_types[path] != :unknown
end
def uri_type(path)
@uri_types[path] == :unknown ? "" : @uri_types[path]
@uri_types[path] == :unknown ? :blob : @uri_types[path]
end
def current_commit
......
......@@ -114,7 +114,7 @@ describe MarkupHelper do
let(:requested_path) { nil }
it 'returns the link to the image path as a relative path' do
expanded_path = "/#{project.full_path}/master/./#{image_file}"
expanded_path = "/#{project.full_path}/-/blob/master/./#{image_file}"
expect(subject.css('a')[0].attr('href')).to eq(expanded_path)
end
......
......@@ -145,7 +145,7 @@ describe Banzai::Filter::RepositoryLinkFilter do
it 'ignores ref if commit is passed' do
doc = filter(link('non/existent.file'), commit: project.commit('empty-branch') )
expect(doc.at_css('a')['href'])
.to eq "/#{project_path}/#{ref}/non/existent.file" # non-existent files have no leading blob/raw/tree
.to eq "/#{project_path}/-/blob/#{ref}/non/existent.file"
end
shared_examples :valid_repository do
......@@ -201,6 +201,12 @@ describe Banzai::Filter::RepositoryLinkFilter do
.to eq "/#{project_path}/-/blob/#{ref}/doc/api/README.md"
end
it 'rebuilds relative URL for a missing file in the repo' do
doc = filter(link('missing-file'))
expect(doc.at_css('a')['href'])
.to eq "/#{project_path}/-/blob/#{ref}/missing-file"
end
it 'rebuilds relative URL for a file in the repo with leading ./' do
doc = filter(link('./doc/api/README.md'))
expect(doc.at_css('a')['href'])
......
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