Class: Gitlab::XmlConverter

Inherits:
ActiveSupport::XMLConverter
  • Object
show all
Defined in:
lib/gitlab/xml_converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml, disallowed_types = nil) ⇒ XmlConverter

Override the default Nokogiri parser in to allow parsing huge XML files



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gitlab/xml_converter.rb', line 9

def initialize(xml, disallowed_types = nil)
  return unless xml.present?

  if xml.size > MAX_XML_SIZE
    raise ArgumentError, format(_("The XML file must be less than %{max_size} MB."),
      max_size: MAX_XML_SIZE / 1.megabyte)
  end

  doc = Nokogiri::XML(xml, &:huge)
  raise doc.errors.first unless doc.errors.empty?

  # These two variables are internally required by `ActiveSupport::XMLConverter`
  @xml = normalize_keys(doc.to_hash)
  @disallowed_types = disallowed_types || DISALLOWED_TYPES
end

Instance Method Details

#to_hObject



25
26
27
28
29
# File 'lib/gitlab/xml_converter.rb', line 25

def to_h
  return unless @xml.present?

  super
end