1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Prefer start_with? and end_with? over regex.

- In one of the cases, filenames were checked for ending with "gz" -
    this is changed to check for ending with ".gz"
  - The change was made to make it even easier to read the code, and to
    match only from the start of the input (as opposed to start of the
    line)

aac4290271
This commit is contained in:
Olle Jonsson 2020-04-19 18:06:02 +02:00 committed by Hiroshi SHIBATA
parent dd5b918cbe
commit f61ee674d8
Notes: git 2020-06-05 07:33:44 +09:00
4 changed files with 7 additions and 5 deletions

View file

@ -456,7 +456,9 @@ class Gem::Command
until extra.empty? do until extra.empty? do
ex = [] ex = []
ex << extra.shift ex << extra.shift
ex << extra.shift if extra.first.to_s =~ /^[^-]/ if (!extra.first.to_s.empty? && !extra.first.to_s.start_with?("-"))
ex << extra.shift
end
result << ex if handles?(ex) result << ex if handles?(ex)
end end

View file

@ -252,7 +252,7 @@ class Gem::RemoteFetcher
data = send "fetch_#{uri.scheme}", uri, mtime, head data = send "fetch_#{uri.scheme}", uri, mtime, head
if data and !head and uri.to_s =~ /\.gz$/ if data and !head and uri.to_s.end_with?(".gz")
begin begin
data = Gem::Util.gunzip data data = Gem::Util.gunzip data
rescue Zlib::GzipFile::Error rescue Zlib::GzipFile::Error

View file

@ -2104,7 +2104,7 @@ class Gem::Specification < Gem::BasicSpecification
end end
if @specification_version > CURRENT_SPECIFICATION_VERSION and if @specification_version > CURRENT_SPECIFICATION_VERSION and
sym.to_s =~ /=$/ sym.to_s.end_with?("=")
warn "ignoring #{sym} loading #{full_name}" if $DEBUG warn "ignoring #{sym} loading #{full_name}" if $DEBUG
else else
super super

View file

@ -49,7 +49,7 @@ class Gem::FakeFetcher
path = path.to_s path = path.to_s
@paths << path @paths << path
raise ArgumentError, 'need full URI' unless path =~ %r{^https?://} raise ArgumentError, 'need full URI' unless path.start_with?("https://", "http://")
unless @data.key? path unless @data.key? path
raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path) raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
@ -67,7 +67,7 @@ class Gem::FakeFetcher
if data.respond_to?(:call) if data.respond_to?(:call)
data.call data.call
else else
if path.to_s =~ /gz$/ and not data.nil? and not data.empty? if path.to_s.end_with?(".gz") and not data.nil? and not data.empty?
data = Gem::Util.gunzip data data = Gem::Util.gunzip data
end end
data data