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:
Diffstat (limited to 'lib/gitlab/front_matter.rb')
-rw-r--r--lib/gitlab/front_matter.rb38
1 files changed, 29 insertions, 9 deletions
diff --git a/lib/gitlab/front_matter.rb b/lib/gitlab/front_matter.rb
index 093501e860b..2a759434b81 100644
--- a/lib/gitlab/front_matter.rb
+++ b/lib/gitlab/front_matter.rb
@@ -8,15 +8,35 @@ module Gitlab
';;;' => 'json'
}.freeze
- DELIM = Regexp.union(DELIM_LANG.keys)
+ DELIM_UNTRUSTED = "(?:#{Gitlab::FrontMatter::DELIM_LANG.keys.map { |x| RE2::Regexp.escape(x) }.join('|')})".freeze
- PATTERN = %r{
- \A(?<encoding>[^\r\n]*coding:[^\r\n]*\R)? # optional encoding line
- (?<before>\s*)
- ^(?<delim>#{DELIM})[ \t]*(?<lang>\S*)\R # opening front matter marker (optional language specifier)
- (?<front_matter>.*?) # front matter block content (not greedy)
- ^(\k<delim> | \.{3}) # closing front matter marker
- [^\S\r\n]*(\R|\z)
- }mx.freeze
+ # Original pattern:
+ # \A(?<encoding>[^\r\n]*coding:[^\r\n]*\R)? # optional encoding line
+ # (?<before>\s*)
+ # ^(?<delim>#{DELIM})[ \t]*(?<lang>\S*)\R # opening front matter marker (optional language specifier)
+ # (?<front_matter>.*?) # front matter block content (not greedy)
+ # ^(\k<delim> | \.{3}) # closing front matter marker
+ # [^\S\r\n]*(\R|\z)
+ # rubocop:disable Style/StringConcatenation
+ # rubocop:disable Style/LineEndConcatenation
+ PATTERN_UNTRUSTED =
+ # optional encoding line
+ "\\A(?P<encoding>[^\\r\\n]*coding:[^\\r\\n]*#{::Gitlab::UntrustedRegexp::BACKSLASH_R})?" +
+ '(?P<before>\s*)' +
+
+ # opening front matter marker (optional language specifier)
+ "^(?P<delim>#{DELIM_UNTRUSTED})[ \\t]*(?P<lang>\\S*)#{::Gitlab::UntrustedRegexp::BACKSLASH_R}" +
+
+ # front matter block content (not greedy)
+ '(?P<front_matter>(?:\n|.)*?)' +
+
+ # closing front matter marker
+ "^((?P<delim_closing>#{DELIM_UNTRUSTED})|\\.{3})" +
+ "[^\\S\\r\\n]*(#{::Gitlab::UntrustedRegexp::BACKSLASH_R}|\\z)"
+ # rubocop:enable Style/LineEndConcatenation
+ # rubocop:enable Style/StringConcatenation
+
+ PATTERN_UNTRUSTED_REGEX =
+ Gitlab::UntrustedRegexp.new(PATTERN_UNTRUSTED, multiline: true)
end
end