BigW Consortium Gitlab

Commit 54459668 by Dmitriy Zaporozhets

Merge branch 'fix-relative-anchored-links' into 'master'

Fix Markdown relative links to files with anchors. Fixes #2016. cc @marin See merge request !1541
parents 0b8e41aa 15bee7e0
......@@ -110,7 +110,7 @@ module GitlabMarkdownHelper
end
def link_to_ignore?(link)
if link =~ /\#\w+/
if link =~ /\A\#\w+/
# ignore anchors like <a href="#my-header">
true
else
......@@ -122,10 +122,11 @@ module GitlabMarkdownHelper
["http://","https://", "ftp://", "mailto:"]
end
def rebuild_path(path)
path.gsub!(/(#.*)/, "")
def rebuild_path(file_path)
file_path = file_path.dup
file_path.gsub!(/(#.*)/, "")
id = $1 || ""
file_path = relative_file_path(path)
file_path = relative_file_path(file_path)
file_path = sanitize_slashes(file_path)
[
......
......@@ -584,7 +584,7 @@ describe GitlabMarkdownHelper do
it "should leave code blocks untouched" do
allow(helper).to receive(:user_color_scheme_class).and_return(:white)
target_html = "<pre class=\"code highlight white plaintext\"><code>some code from $40\nhere too\n</code></pre>\n"
target_html = "<pre class=\"code highlight white plaintext\"><code>some code from $#{snippet.id}\nhere too\n</code></pre>\n"
expect(helper.markdown("\n some code from $#{snippet.id}\n here too\n")).
to eq(target_html)
......@@ -638,6 +638,18 @@ describe GitlabMarkdownHelper do
expect(markdown(actual)).to match(expected)
end
it "should handle relative urls for a file in master with an anchor" do
actual = "[GitLab API doc](doc/api/README.md#section)\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/blob/#{@ref}/doc/api/README.md#section\">GitLab API doc</a></p>\n"
expect(markdown(actual)).to match(expected)
end
it "should not handle relative urls for the current file with an anchor" do
actual = "[GitLab API doc](#section)\n"
expected = "<p><a href=\"#section\">GitLab API doc</a></p>\n"
expect(markdown(actual)).to match(expected)
end
it "should handle relative urls for a directory in master" do
actual = "[GitLab API doc](doc/api)\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/tree/#{@ref}/doc/api\">GitLab API doc</a></p>\n"
......
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