Fix links to uploaded files on wiki pages
This commit is contained in:
parent
0f449ecc37
commit
31e5921989
3 changed files with 17 additions and 0 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix links to uploaded files on wiki pages
|
||||||
|
merge_request: 16499
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -9,6 +9,10 @@ module Banzai
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_rules
|
def apply_rules
|
||||||
|
# Special case: relative URLs beginning with `/uploads/` refer to
|
||||||
|
# user-uploaded files and will be handled elsewhere.
|
||||||
|
return @uri.to_s if @uri.relative? && @uri.path.starts_with?('/uploads/')
|
||||||
|
|
||||||
apply_file_link_rules!
|
apply_file_link_rules!
|
||||||
apply_hierarchical_link_rules!
|
apply_hierarchical_link_rules!
|
||||||
apply_relative_link_rules!
|
apply_relative_link_rules!
|
||||||
|
|
|
@ -10,15 +10,23 @@ describe Banzai::Filter::WikiLinkFilter do
|
||||||
|
|
||||||
it "doesn't rewrite absolute links" do
|
it "doesn't rewrite absolute links" do
|
||||||
filtered_link = filter("<a href='http://example.com:8000/'>Link</a>", project_wiki: wiki).children[0]
|
filtered_link = filter("<a href='http://example.com:8000/'>Link</a>", project_wiki: wiki).children[0]
|
||||||
|
|
||||||
expect(filtered_link.attribute('href').value).to eq('http://example.com:8000/')
|
expect(filtered_link.attribute('href').value).to eq('http://example.com:8000/')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't rewrite links to project uploads" do
|
||||||
|
filtered_link = filter("<a href='/uploads/a.test'>Link</a>", project_wiki: wiki).children[0]
|
||||||
|
|
||||||
|
expect(filtered_link.attribute('href').value).to eq('/uploads/a.test')
|
||||||
|
end
|
||||||
|
|
||||||
describe "invalid links" do
|
describe "invalid links" do
|
||||||
invalid_links = ["http://:8080", "http://", "http://:8080/path"]
|
invalid_links = ["http://:8080", "http://", "http://:8080/path"]
|
||||||
|
|
||||||
invalid_links.each do |invalid_link|
|
invalid_links.each do |invalid_link|
|
||||||
it "doesn't rewrite invalid invalid_links like #{invalid_link}" do
|
it "doesn't rewrite invalid invalid_links like #{invalid_link}" do
|
||||||
filtered_link = filter("<a href='#{invalid_link}'>Link</a>", project_wiki: wiki).children[0]
|
filtered_link = filter("<a href='#{invalid_link}'>Link</a>", project_wiki: wiki).children[0]
|
||||||
|
|
||||||
expect(filtered_link.attribute('href').value).to eq(invalid_link)
|
expect(filtered_link.attribute('href').value).to eq(invalid_link)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue