diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index 7039bdc..65b64ea 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -75,12 +75,12 @@ module GitlabMarkdownHelper def new_link(path_with_namespace, string, ref) [ path_with_namespace, - path(string, ref), + path_with_ref(string, ref), string ].compact.join("/") end - def path(string, ref) + def path_with_ref(string, ref) if File.exists?(Rails.root.join(string)) "#{local_path(string)}/#{correct_ref(ref)}" else diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index d49247a..a0bbc02 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -406,6 +406,30 @@ describe GitlabMarkdownHelper do it "should generate absolute urls for emoji" do markdown(":smile:").should include("src=\"#{url_to_image("emoji/smile")}") end + + it "should handle relative urls for a file in master" do + actual = "[GitLab API doc](doc/api/README.md)\n" + expected = "

GitLab API doc

\n" + markdown(actual).should match(expected) + end + + it "should handle relative urls for a directory in master" do + actual = "[GitLab API doc](doc/api)\n" + expected = "

GitLab API doc

\n" + markdown(actual).should match(expected) + end + + it "should handle absolute urls" do + actual = "[GitLab](https://www.gitlab.com)\n" + expected = "

GitLab

\n" + markdown(actual).should match(expected) + end + + it "should handle wiki urls" do + actual = "[Link](test/link)\n" + expected = "

Link

\n" + markdown(actual).should match(expected) + end end describe "#render_wiki_content" do -- libgit2 0.21.2