Commit fdb0d197 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'improve-markdwon-render' into 'master'

Improve markdwon parsing

Fix 500 error when try to use relative links in project issues if repository is empty
parents a34dabd8 1e673c72
......@@ -63,11 +63,15 @@ module GitlabMarkdownHelper
paths = extract_paths(text)
paths.uniq.each do |file_path|
# If project does not have repository
# its nothing to rebuild
if @repository.exists? && !@repository.empty?
new_path = rebuild_path(file_path)
# Finds quoted path so we don't replace other mentions of the string
# eg. "doc/api" will be replaced and "/home/doc/api/text" won't
text.gsub!("\"#{file_path}\"", "\"/#{new_path}\"")
end
end
text
end
......@@ -91,8 +95,13 @@ module GitlabMarkdownHelper
end
def link_to_ignore?(link)
if link =~ /\#\w+/
# ignore anchors like <a href="#my-header">
true
else
ignored_protocols.map{ |protocol| link.include?(protocol) }.any?
end
end
def ignored_protocols
["http://","https://", "ftp://", "mailto:"]
......@@ -169,7 +178,7 @@ module GitlabMarkdownHelper
def current_sha
if @commit
@commit.id
else
elsif @repository && !@repository.empty?
@repository.head_commit.sha
end
end
......
......@@ -5,6 +5,7 @@ describe GitlabMarkdownHelper do
include IssuesHelper
let!(:project) { create(:project) }
let(:empty_project) { create(:empty_project) }
let(:user) { create(:user, username: 'gfm') }
let(:commit) { project.repository.commit }
......@@ -506,6 +507,19 @@ describe GitlabMarkdownHelper do
end
end
describe "markdwon for empty repository" do
before do
@project = empty_project
@repository = empty_project.repository
end
it "should not touch relative urls" do
actual = "[GitLab API doc][GitLab readme]\n [GitLab readme]: doc/api/README.md\n"
expected = "<p><a href=\"doc/api/README.md\">GitLab API doc</a></p>\n"
markdown(actual).should match(expected)
end
end
describe "#render_wiki_content" do
before do
@wiki = double('WikiPage')
......
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