diff options
author | Sean McGivern <sean@gitlab.com> | 2018-10-15 11:42:15 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-10-16 10:54:49 +0100 |
commit | 0bcfd0adb303f0fcaac40b703deda49f3dd683f4 (patch) | |
tree | dc4f44b2019a47e577bf75a7f2964d14a6655c1d /lib | |
parent | c7fd95584eb2a595d84a5693a14b4b46c2885251 (diff) | |
download | gitlab-ce-0bcfd0adb303f0fcaac40b703deda49f3dd683f4.tar.gz |
Fix image webhook rewriting for uploads
This rewrote URLs to be absolute URLs. However, for uploads (the most
common case), we actually need them to point to not just the GitLab
instance, but the project they're from. Thankfully, we can normally get
that information from the object we're building the hook for.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/hook_data/base_builder.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/gitlab/hook_data/base_builder.rb b/lib/gitlab/hook_data/base_builder.rb index 4ffca356b29..1a91301e8be 100644 --- a/lib/gitlab/hook_data/base_builder.rb +++ b/lib/gitlab/hook_data/base_builder.rb @@ -25,6 +25,7 @@ module Gitlab markdown_text.gsub(MARKDOWN_SIMPLE_IMAGE) do if $~[:image] url = $~[:url] + url = "#{uploads_prefix}#{url}" if url.start_with?('/uploads') url = "/#{url}" unless url.start_with?('/') "![#{$~[:title]}](#{Gitlab.config.gitlab.url}#{url})" @@ -33,6 +34,16 @@ module Gitlab end end end + + def uploads_prefix + project&.full_path || '' + end + + def project + return unless object.respond_to?(:project) + + object.project + end end end end |