summaryrefslogtreecommitdiff
path: root/lib/cgi
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-08-19 16:37:29 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-08-19 16:39:42 +0900
commit45454bdb8b25def782677dceb92cfd7b2d8b83c1 (patch)
treee2f4ee642cd3bbfb0a0c73f8015ab4333862c9f0 /lib/cgi
parentb4daa442704204b93a586fb7b696998f33b29c72 (diff)
Prefer Regexp#=~ to Regexp#match when the RHS may be nil
Diffstat (limited to 'lib/cgi')
-rw-r--r--lib/cgi/cookie.rb10
-rw-r--r--lib/cgi/core.rb5
2 files changed, 5 insertions, 10 deletions
diff --git a/lib/cgi/cookie.rb b/lib/cgi/cookie.rb
index 99f4b20f56..ae9ab58ede 100644
--- a/lib/cgi/cookie.rb
+++ b/lib/cgi/cookie.rb
@@ -73,8 +73,7 @@ class CGI
@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
@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 ac0d2d3cb3..ac75e54139 100644
--- a/lib/cgi/core.rb
+++ b/lib/cgi/core.rb
@@ -261,7 +261,7 @@ class CGI
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
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
# 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