Class: Gitlab::WikiPages::FrontMatterParser
- Inherits:
-
Object
- Object
- Gitlab::WikiPages::FrontMatterParser
- Defined in:
- lib/gitlab/wiki_pages/front_matter_parser.rb
Defined Under Namespace
Constant Summary collapse
- MAX_SLUGS =
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 - a "slugs:" line - and up to 50 slugs
This limit does not take comments into account.
50
- SLUG_LINE_LENGTH =
(4 + Gitlab::WikiPages::MAX_DIRECTORY_BYTES + 1 + Gitlab::WikiPages::MAX_TITLE_BYTES)
- MAX_FRONT_MATTER_LENGTH =
(8 + Gitlab::WikiPages::MAX_TITLE_BYTES) + 7 + (SLUG_LINE_LENGTH * MAX_SLUGS)
- ParseError =
Class.new(StandardError)
Instance Method Summary collapse
-
#initialize(wiki_content) ⇒ FrontMatterParser
constructor
A new instance of FrontMatterParser.
- #parse ⇒ Object
Constructor Details
#initialize(wiki_content) ⇒ FrontMatterParser
Returns a new instance of FrontMatterParser.
31 32 33 |
# File 'lib/gitlab/wiki_pages/front_matter_parser.rb', line 31 def initialize(wiki_content) @wiki_content = wiki_content end |
Instance Method Details
#parse ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/gitlab/wiki_pages/front_matter_parser.rb', line 35 def parse return empty_result unless wiki_content.present? return empty_result(block.error) unless block.valid? Result.new(front_matter: block.data, content: strip_front_matter_block) rescue ParseError => error empty_result(:parse_error, error) end |