Commit 22055e10 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Fix a few edited references from WikiLinkFilter and specs

parent 61fe0a23
...@@ -25,10 +25,10 @@ module Banzai ...@@ -25,10 +25,10 @@ module Banzai
end end
def process_link_attr(html_attr) def process_link_attr(html_attr)
return if html_attr.blank? return if html_attr.blank? || file_reference?(html_attr)
uri = URI(html_attr.value) uri = URI(html_attr.value)
if uri.relative? && uri.path.present? && uri.path if uri.relative? && uri.path.present?
html_attr.value = rebuild_wiki_uri(uri).to_s html_attr.value = rebuild_wiki_uri(uri).to_s
end end
rescue URI::Error rescue URI::Error
...@@ -40,6 +40,10 @@ module Banzai ...@@ -40,6 +40,10 @@ module Banzai
uri uri
end end
def file_reference?(html_attr)
!File.extname(html_attr.value).blank?
end
def project_wiki def project_wiki
context[:project_wiki] context[:project_wiki]
end end
......
...@@ -230,6 +230,7 @@ describe 'GitLab Markdown', feature: true do ...@@ -230,6 +230,7 @@ describe 'GitLab Markdown', feature: true do
file = Gollum::File.new(@project_wiki.wiki) file = Gollum::File.new(@project_wiki.wiki)
expect(file).to receive(:path).and_return('images/example.jpg') expect(file).to receive(:path).and_return('images/example.jpg')
expect(@project_wiki).to receive(:find_file).with('images/example.jpg').and_return(file) expect(@project_wiki).to receive(:find_file).with('images/example.jpg').and_return(file)
allow(@project_wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' }
@html = markdown(@feat.raw_markdown, { pipeline: :wiki, project_wiki: @project_wiki }) @html = markdown(@feat.raw_markdown, { pipeline: :wiki, project_wiki: @project_wiki })
end end
......
...@@ -13,7 +13,7 @@ module MarkdownMatchers ...@@ -13,7 +13,7 @@ module MarkdownMatchers
set_default_markdown_messages set_default_markdown_messages
match do |actual| match do |actual|
link = actual.at_css('a:contains("Relative Link")') link = actual.at_css('a:contains("Relative Link")')
image = actual.at_css('img[alt="Relative Image"]') image = actual.at_css('img[alt="Relative Image"]')
expect(link['href']).to end_with('master/doc/README.md') expect(link['href']).to end_with('master/doc/README.md')
...@@ -72,14 +72,15 @@ module MarkdownMatchers ...@@ -72,14 +72,15 @@ module MarkdownMatchers
have_css("img[src$='#{src}']") have_css("img[src$='#{src}']")
end end
prefix = '/namespace1/gitlabhq/wikis'
set_default_markdown_messages set_default_markdown_messages
match do |actual| match do |actual|
expect(actual).to have_link('linked-resource', href: 'linked-resource') expect(actual).to have_link('linked-resource', href: "#{prefix}/linked-resource")
expect(actual).to have_link('link-text', href: 'linked-resource') expect(actual).to have_link('link-text', href: "#{prefix}/linked-resource")
expect(actual).to have_link('http://example.com', href: 'http://example.com') expect(actual).to have_link('http://example.com', href: 'http://example.com')
expect(actual).to have_link('link-text', href: 'http://example.com/pdfs/gollum.pdf') expect(actual).to have_link('link-text', href: 'http://example.com/pdfs/gollum.pdf')
expect(actual).to have_image('/gitlabhq/wikis/images/example.jpg') expect(actual).to have_image("#{prefix}/images/example.jpg")
expect(actual).to have_image('http://example.com/images/example.jpg') expect(actual).to have_image('http://example.com/images/example.jpg')
end end
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