diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-22 00:27:02 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-22 00:27:02 +0000 |
commit | 615ac3593499f54fde4b1eb0fba66b6bd944821b (patch) | |
tree | 1f0b0e97ee3dd51798658d53cee7eec976a83a97 /lib/rubygems/specification_policy.rb | |
parent | ff31b35f6a66f3c1548e3356d506ff65a574be7f (diff) |
Merge rubygems master branch from github.com/rubygems/rubygems.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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 |