method

validate_metadata

Importance_0
Ruby latest stable (v2_5_5) - 0 notes - Class: Specification
validate_metadata() public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/rubygems/specification.rb, line 2872
  def validate_metadata
    url_validation_regex = %{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z}
    link_keys = %(
      bug_tracker_uri
      changelog_uri
      documentation_uri
      homepage_uri
      mailing_list_uri
      source_code_uri
      wiki_uri
    )

    metadata.each do|key, value|
      if !key.kind_of?(String)
        raise Gem::InvalidSpecificationException,
                "metadata keys must be a String"
      end

      if key.size > 128
        raise Gem::InvalidSpecificationException,
                "metadata key too large (#{key.size} > 128)"
      end

      if !value.kind_of?(String)
        raise Gem::InvalidSpecificationException,
                "metadata values must be a String"
      end

      if value.size > 1024
        raise Gem::InvalidSpecificationException,
                "metadata value too large (#{value.size} > 1024)"
      end

      if link_keys.include? key
        if value !~ url_validation_regex
          raise Gem::InvalidSpecificationException,
                 "metadata['#{key}'] has invalid link: #{value.inspect}"
        end
      end
    end
  end
Register or log in to add new notes.