Skip to content

Commit

Permalink
Make sure relative url and asset_host are honored, specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlazio committed Oct 10, 2014
1 parent 4149fc2 commit 2ea166f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ GEM
html-pipeline (1.11.0)
activesupport (>= 2)
nokogiri (~> 1.4)
html-pipeline-gitlab (0.1.4)
html-pipeline-gitlab (0.1.5)
actionpack (~> 4)
gitlab_emoji (~> 0.0.1)
html-pipeline (~> 1.11.0)
Expand Down
7 changes: 6 additions & 1 deletion lib/gitlab/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,14 @@ def gfm(text, project = @project, html_options = {})
HTML::Pipeline::Gitlab::GitlabEmojiFilter
]

markdown_context = {
asset_root: Gitlab.config.gitlab.url,
asset_host: Gitlab::Application.config.asset_host
}

markdown_pipeline = HTML::Pipeline::Gitlab.new(filters).pipeline

result = markdown_pipeline.call(text)
result = markdown_pipeline.call(text, markdown_context)
text = result[:output].to_html(save_with: 0)

allowed_attributes = ActionView::Base.sanitized_allowed_attributes
Expand Down
14 changes: 13 additions & 1 deletion spec/helpers/gitlab_markdown_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,21 @@ def url_helper(image_name)
end

it "should generate absolute urls for emoji" do
markdown(":smile:").should include("src=\"#{url_helper('emoji/smile')}")
markdown(":smile:").should include("src=\"http://localhost/assets/emoji/smile.png")
end

it "should generate absolute urls for emoji if relative url is present" do
Gitlab.config.gitlab.stub(:url).and_return('http://localhost/gitlab/root')
markdown(":smile:").should include("src=\"http://localhost/gitlab/root/assets/emoji/smile.png")
end

it "should generate absolute urls for emoji if asset_host is present" do
Gitlab::Application.config.stub(:asset_host).and_return("https://cdn.example.com")
ActionView::Base.any_instance.stub_chain(:config, :asset_host).and_return("https://cdn.example.com")
markdown(":smile:").should include("src=\"https://cdn.example.com/assets/emoji/smile.png")
end


it "should handle relative urls for a file in master" do
actual = "[GitLab API doc](doc/api/README.md)\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/blob/#{@ref}/doc/api/README.md\">GitLab API doc</a></p>\n"
Expand Down

0 comments on commit 2ea166f

Please sign in to comment.