From 45454bdb8b25def782677dceb92cfd7b2d8b83c1 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 19 Aug 2019 16:37:29 +0900 Subject: Prefer Regexp#=~ to Regexp#match when the RHS may be nil --- lib/cgi/cookie.rb | 10 ++-------- lib/cgi/core.rb | 5 +++-- 2 files changed, 5 insertions(+), 10 deletions(-) (limited to 'lib/cgi') 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 -- cgit v1.2.3