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 ...@@ -63,11 +63,15 @@ module GitlabMarkdownHelper
paths = extract_paths(text) paths = extract_paths(text)
paths.uniq.each do |file_path| 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) new_path = rebuild_path(file_path)
# Finds quoted path so we don't replace other mentions of the string # 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 # eg. "doc/api" will be replaced and "/home/doc/api/text" won't
text.gsub!("\"#{file_path}\"", "\"/#{new_path}\"") text.gsub!("\"#{file_path}\"", "\"/#{new_path}\"")
end end
end
text text
end end
...@@ -91,8 +95,13 @@ module GitlabMarkdownHelper ...@@ -91,8 +95,13 @@ module GitlabMarkdownHelper
end end
def link_to_ignore?(link) 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? ignored_protocols.map{ |protocol| link.include?(protocol) }.any?
end end
end
def ignored_protocols def ignored_protocols
["http://","https://", "ftp://", "mailto:"] ["http://","https://", "ftp://", "mailto:"]
...@@ -169,7 +178,7 @@ module GitlabMarkdownHelper ...@@ -169,7 +178,7 @@ module GitlabMarkdownHelper
def current_sha def current_sha
if @commit if @commit
@commit.id @commit.id
else elsif @repository && !@repository.empty?
@repository.head_commit.sha @repository.head_commit.sha
end end
end end
......
...@@ -5,6 +5,7 @@ describe GitlabMarkdownHelper do ...@@ -5,6 +5,7 @@ describe GitlabMarkdownHelper do
include IssuesHelper include IssuesHelper
let!(:project) { create(:project) } let!(:project) { create(:project) }
let(:empty_project) { create(:empty_project) }
let(:user) { create(:user, username: 'gfm') } let(:user) { create(:user, username: 'gfm') }
let(:commit) { project.repository.commit } let(:commit) { project.repository.commit }
...@@ -506,6 +507,19 @@ describe GitlabMarkdownHelper do ...@@ -506,6 +507,19 @@ describe GitlabMarkdownHelper do
end end
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 describe "#render_wiki_content" do
before do before do
@wiki = double('WikiPage') @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