[前][次][番号順一覧][スレッド一覧]

ruby-changes:57176

From: Nobuyoshi <ko1@a...>
Date: Mon, 19 Aug 2019 16:40:12 +0900 (JST)
Subject: [ruby-changes:57176] Nobuyoshi Nakada: 45454bdb8b (master): Prefer Regexp#=~ to Regexp#match when the RHS may be nil

https://git.ruby-lang.org/ruby.git/commit/?id=45454bdb8b

From 45454bdb8b25def782677dceb92cfd7b2d8b83c1 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 19 Aug 2019 16:37:29 +0900
Subject: Prefer Regexp#=~ to Regexp#match when the RHS may be nil


diff --git a/lib/cgi/cookie.rb b/lib/cgi/cookie.rb
index 99f4b20..ae9ab58 100644
--- a/lib/cgi/cookie.rb
+++ b/lib/cgi/cookie.rb
@@ -73,8 +73,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/cookie.rb#L73
       @expires = nil
       if name.kind_of?(String)
         @name = name
-        %r|^(.*/)|.match(ENV["SCRIPT_NAME"])
-        @path = ($1 or "")
+        @path = (%r|\A(.*/)| =~ ENV["SCRIPT_NAME"] ? $1 : "")
         @secure = false
         @httponly = false
         return super(value)
@@ -88,12 +87,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/cookie.rb#L87
       @name = options["name"]
       value = Array(options["value"])
       # simple support for IE
-      if options["path"]
-        @path = options["path"]
-      else
-        %r|^(.*/)|.match(ENV["SCRIPT_NAME"])
-        @path = ($1 or "")
-      end
+      @path = options["path"] || (%r|\A(.*/)| =~ ENV["SCRIPT_NAME"] ? $1 : "")
       @domain = options["domain"]
       @expires = options["expires"]
       @secure = options["secure"] == true
diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb
index ac0d2d3..ac75e54 100644
--- a/lib/cgi/core.rb
+++ b/lib/cgi/core.rb
@@ -261,7 +261,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/core.rb#L261
   private :_header_for_hash
 
   def nph?  #:nodoc:
-    return /IIS\/(\d+)/.match($CGI_ENV['SERVER_SOFTWARE']) && $1.to_i < 5
+    return /IIS\/(\d+)/ =~ $CGI_ENV['SERVER_SOFTWARE'] && $1.to_i < 5
   end
 
   def _header_for_modruby(buf)  #:nodoc:
@@ -607,6 +607,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/core.rb#L607
     end
     def unescape_filename?  #:nodoc:
       user_agent = $CGI_ENV['HTTP_USER_AGENT']
+      return false unless user_agent
       return /Mac/i.match(user_agent) && /Mozilla/i.match(user_agent) && !/MSIE/i.match(user_agent)
     end
 
@@ -648,7 +649,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/core.rb#L649
     # Reads query parameters in the @params field, and cookies into @cookies.
     def initialize_query()
       if ("POST" == env_table['REQUEST_METHOD']) and
-        %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|.match(env_table['CONTENT_TYPE'])
+        %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?| =~ env_table['CONTENT_TYPE']
         current_max_multipart_length = @max_multipart_length.respond_to?(:call) ? @max_multipart_length.call : @max_multipart_length
         raise StandardError.new("too large multipart data.") if env_table['CONTENT_LENGTH'].to_i > current_max_multipart_length
         boundary = $1.dup
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]