diff options
Diffstat (limited to 'lib/rubygems/specification_policy.rb')
-rw-r--r-- | lib/rubygems/specification_policy.rb | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index d117120e9a..e28408a5a5 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -4,6 +4,8 @@ require 'uri' class Gem::SpecificationPolicy < SimpleDelegator VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/ # :nodoc: + SPECIAL_CHARACTERS = /\A[#{Regexp.escape('.-_')}]+/ # :nodoc: + VALID_URI_PATTERN = %r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z} # :nodoc: METADATA_LINK_KEYS = %w[ @@ -14,7 +16,7 @@ class Gem::SpecificationPolicy < SimpleDelegator mailing_list_uri source_code_uri wiki_uri - ] # :nodoc: + ].freeze # :nodoc: def initialize(specification) @warnings = 0 @@ -219,12 +221,14 @@ open-ended dependency on #{dep} is not recommended end def validate_name - if !name.is_a?(String) then + if !name.is_a?(String) error "invalid value for attribute name: \"#{name.inspect}\" must be a string" - elsif name !~ /[a-zA-Z]/ then + elsif name !~ /[a-zA-Z]/ error "invalid value for attribute name: #{name.dump} must include at least one letter" - elsif name !~ VALID_NAME_PATTERN then + elsif name !~ VALID_NAME_PATTERN error "invalid value for attribute name: #{name.dump} can only include letters, numbers, dashes, and underscores" + elsif name =~ SPECIAL_CHARACTERS + error "invalid value for attribute name: #{name.dump} can not begin with a period, dash, or underscore" end end @@ -257,9 +261,9 @@ open-ended dependency on #{dep} is not recommended def validate_platform case platform - when Gem::Platform, Gem::Platform::RUBY then # ok - else - error "invalid platform #{platform.inspect}, see Gem::Platform" + when Gem::Platform, Gem::Platform::RUBY then # ok + else + error "invalid platform #{platform.inspect}, see Gem::Platform" end end @@ -272,10 +276,10 @@ open-ended dependency on #{dep} is not recommended def validate_array_attribute(field) val = self.send(field) klass = case field - when :dependencies then - Gem::Dependency - else - String + when :dependencies then + Gem::Dependency + else + String end unless Array === val and val.all? {|x| x.kind_of?(klass)} then |