diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-29 21:09:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-29 21:09:17 +0300 |
commit | 2516f0d87bf4504cf0d626a0584b2eebe459749b (patch) | |
tree | 52d1188485f7362da9d87b526e14e49be00fa9a1 /lib/gitlab/changelog | |
parent | 10052df7536415c192788799b294c9a5ecf07ce7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/changelog')
-rw-r--r-- | lib/gitlab/changelog/committer.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/changelog/config.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/changelog/template/compiler.rb | 16 |
3 files changed, 25 insertions, 7 deletions
diff --git a/lib/gitlab/changelog/committer.rb b/lib/gitlab/changelog/committer.rb index d2563590bed..617017faa58 100644 --- a/lib/gitlab/changelog/committer.rb +++ b/lib/gitlab/changelog/committer.rb @@ -26,7 +26,13 @@ module Gitlab # scratch, otherwise we may end up throwing away changes. As such, all # the logic is contained within the retry block. Retriable.retriable(on: CommitError) do - commit = @project.commit(branch) + commit = Gitlab::Git::Commit.last_for_path( + @project.repository, + branch, + file, + literal_pathspec: true + ) + content = blob_content(file, commit) # If the release has already been added (e.g. concurrently by another diff --git a/lib/gitlab/changelog/config.rb b/lib/gitlab/changelog/config.rb index ac62572576e..3f06b612687 100644 --- a/lib/gitlab/changelog/config.rb +++ b/lib/gitlab/changelog/config.rb @@ -37,7 +37,10 @@ module Gitlab end if (template = hash['template']) - config.template = Template::Compiler.new.compile(template) + # We use the full namespace here (and further down) as otherwise Rails + # may use the wrong constant when autoloading is used. + config.template = + ::Gitlab::Changelog::Template::Compiler.new.compile(template) end if (categories = hash['categories']) @@ -54,7 +57,8 @@ module Gitlab def initialize(project) @project = project @date_format = DEFAULT_DATE_FORMAT - @template = Template::Compiler.new.compile(DEFAULT_TEMPLATE) + @template = + ::Gitlab::Changelog::Template::Compiler.new.compile(DEFAULT_TEMPLATE) @categories = {} end diff --git a/lib/gitlab/changelog/template/compiler.rb b/lib/gitlab/changelog/template/compiler.rb index f67bab0f29f..fa7724aa2da 100644 --- a/lib/gitlab/changelog/template/compiler.rb +++ b/lib/gitlab/changelog/template/compiler.rb @@ -98,19 +98,27 @@ module Gitlab ESCAPED_NEWLINE = /\\\n$/.freeze # The start tag for ERB tags. These tags will be escaped, preventing - # users FROM USING erb DIRECTLY. - ERB_START_TAG = '<%' + # users from using ERB directly. + ERB_START_TAG = /<\\?\s*\\?\s*%/.freeze def compile(template) transformed_lines = ['<% it = variables %>'] + # ERB tags must be stripped here, otherwise a user may introduce ERB + # tags by making clever use of whitespace. See + # https://gitlab.com/gitlab-org/gitlab/-/issues/300224 for more + # information. + template = template.gsub(ERB_START_TAG, '<%%') + template.each_line { |line| transformed_lines << transform(line) } - Template.new(transformed_lines.join) + + # We use the full namespace here as otherwise Rails may use the wrong + # constant when autoloading is used. + ::Gitlab::Changelog::Template::Template.new(transformed_lines.join) end def transform(line) line.gsub!(ESCAPED_NEWLINE, '') - line.gsub!(ERB_START_TAG, '<%%') # This replacement ensures that "end" blocks on their own lines # don't add extra newlines. Using an ERB -%> tag sadly swallows too |