Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 19:05:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 19:05:49 +0300
commit43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch)
treedceebdc68925362117480a5d672bcff122fb625b /lib/gitlab/hook_data
parent20c84b99005abd1c82101dfeff264ac50d2df211 (diff)
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'lib/gitlab/hook_data')
-rw-r--r--lib/gitlab/hook_data/base_builder.rb30
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/gitlab/hook_data/base_builder.rb b/lib/gitlab/hook_data/base_builder.rb
index e5bae61ae4e..4a81f6b8a0e 100644
--- a/lib/gitlab/hook_data/base_builder.rb
+++ b/lib/gitlab/hook_data/base_builder.rb
@@ -5,15 +5,14 @@ module Gitlab
class BaseBuilder
attr_accessor :object
- MARKDOWN_SIMPLE_IMAGE = %r{
- #{::Gitlab::Regex.markdown_code_or_html_blocks}
- |
- (?<image>
- !
- \[(?<title>[^\n]*?)\]
- \((?<url>(?!(https?://|//))[^\n]+?)\)
- )
- }mx.freeze
+ MARKDOWN_SIMPLE_IMAGE =
+ "#{::Gitlab::Regex.markdown_code_or_html_blocks_untrusted}" \
+ '|' \
+ '(?P<image>' \
+ '!' \
+ '\[(?P<title>[^\n]*?)\]' \
+ '\((?P<url>(?P<https>(https?://|//)?)[^\n]+?)\)' \
+ ')'.freeze
def initialize(object)
@object = object
@@ -37,15 +36,18 @@ module Gitlab
def absolute_image_urls(markdown_text)
return markdown_text unless markdown_text.present?
- markdown_text.gsub(MARKDOWN_SIMPLE_IMAGE) do
- if $~[:image]
- url = $~[:url]
+ regex = Gitlab::UntrustedRegexp.new(MARKDOWN_SIMPLE_IMAGE, multiline: false)
+ return markdown_text unless regex.match?(markdown_text)
+
+ regex.replace_gsub(markdown_text) do |match|
+ if match[:image] && !match[:https]
+ url = match[:url]
url = "#{uploads_prefix}#{url}" if url.start_with?('/uploads')
url = "/#{url}" unless url.start_with?('/')
- "![#{$~[:title]}](#{Gitlab.config.gitlab.url}#{url})"
+ "![#{match[:title]}](#{Gitlab.config.gitlab.url}#{url})"
else
- $~[0]
+ match.to_s
end
end
end