summaryrefslogtreecommitdiff
path: root/lib/cgi/cookie.rb
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/cookie.rb
parentb4daa442704204b93a586fb7b696998f33b29c72 (diff)
Prefer Regexp#=~ to Regexp#match when the RHS may be nil
Diffstat (limited to 'lib/cgi/cookie.rb')
-rw-r--r--lib/cgi/cookie.rb10
1 files changed, 2 insertions, 8 deletions
diff --git a/lib/cgi/cookie.rb b/lib/cgi/cookie.rb
index 99f4b20f56f..ae9ab58edef 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