Skip to content

Fix multi document YAML format when empty documents are used

Grzegorz Bizon requested to merge fix/gb/fix-empty-multi-doc-yaml into master

What does this MR do and why?

This merge request fixes multi-doc YAML format when empty documents are being used, for example:

---
test:
  script: echo "ok"
---

This should be a valid document, however, a nil one had been created before the fix:

From: /home/git/gitlab/lib/gitlab/config/loader/multi_doc_yaml.rb:44 Gitlab::Config::Loader::MultiDocYaml#documents:

    39:                   .split(MULTI_DOC_DIVIDER, max_documents_including_leading_delimiter)
    40:                   .map { |d| Yaml.new(d, additional_permitted_classes: additional_permitted_classes) }
    41: 
    42:           docs.shift if docs.first.blank?
    43:           binding.pry
 => 44:           docs
    45:         end
    46:         strong_memoize_attr :documents
    47: 
    48:         def max_documents_including_leading_delimiter
    49:           max_documents + 1

[1] pry(#<Gitlab::Config::Loader::MultiDocYaml>)> docs
=> [#<Gitlab::Config::Loader::Yaml:0x00007fc38e2fcac0 @config={"test"=>{"script"=>"echo \"ok\""}}>, #<Gitlab::Config::Loader::Yaml:0x00007fc38e2f7c00 @config=nil>]

/cc @fabiopitino @avielle

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports