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>2022-07-09 00:08:40 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-09 00:08:40 +0300
commit79959cb5bc84ba8274ca3a6caa7ff88c86a80caa (patch)
tree93aae2860f63c661ac5718692d7804b84fb3a7d1 /lib/gitlab/wiki_pages
parentb9664970c3f8ac8c80e26052af098b1c9b09616c (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/wiki_pages')
-rw-r--r--lib/gitlab/wiki_pages/front_matter_parser.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/gitlab/wiki_pages/front_matter_parser.rb b/lib/gitlab/wiki_pages/front_matter_parser.rb
index ee30fa907f4..071b0dde619 100644
--- a/lib/gitlab/wiki_pages/front_matter_parser.rb
+++ b/lib/gitlab/wiki_pages/front_matter_parser.rb
@@ -3,6 +3,8 @@
module Gitlab
module WikiPages
class FrontMatterParser
+ FEATURE_FLAG = :wiki_front_matter
+
# We limit the maximum length of text we are prepared to parse as YAML, to
# avoid exploitations and attempts to consume memory and CPU. We allow for:
# - a title line
@@ -28,12 +30,18 @@ module Gitlab
end
# @param [String] wiki_content
- def initialize(wiki_content)
+ # @param [FeatureGate] feature_gate The scope for feature availability
+ def initialize(wiki_content, feature_gate)
@wiki_content = wiki_content
+ @feature_gate = feature_gate
+ end
+
+ def self.enabled?(gate = nil)
+ Feature.enabled?(FEATURE_FLAG, gate)
end
def parse
- return empty_result unless wiki_content.present?
+ return empty_result unless enabled? && wiki_content.present?
return empty_result(block.error) unless block.valid?
Result.new(front_matter: block.data, content: strip_front_matter_block)
@@ -86,12 +94,16 @@ module Gitlab
private
- attr_reader :wiki_content
+ attr_reader :wiki_content, :feature_gate
def empty_result(reason = nil, error = nil)
Result.new(content: wiki_content, reason: reason, error: error)
end
+ def enabled?
+ self.class.enabled?(feature_gate)
+ end
+
def block
@block ||= parse_front_matter_block
end