Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rubocop Offenses #47508

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions actionpack/lib/action_dispatch/middleware/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def handle_options(options)

if options[:domain] == :all || options[:domain] == "all"
cookie_domain = ""
dot_splitted_host = request.host.split('.', -1)
dot_splitted_host = request.host.split(".", -1)

# Case where request.host is not an IP address or it's an invalid domain
# (ip confirms to the domain structure we expect so we explicitly check for ip)
Expand All @@ -446,10 +446,10 @@ def handle_options(options)
end

# If there is a provided tld length then we use it otherwise default domain.
if options[:tld_length].present?
if options[:tld_length].present?
# Case where the tld_length provided is valid
if dot_splitted_host.length >= options[:tld_length]
cookie_domain = dot_splitted_host.last(options[:tld_length]).join('.')
cookie_domain = dot_splitted_host.last(options[:tld_length]).join(".")
end
# Case where tld_length is not provided
else
Expand All @@ -458,7 +458,7 @@ def handle_options(options)
cookie_domain = dot_splitted_host.last(2).join(".")
# **.**, ***.** style TLDs like co.uk and com.au
else
cookie_domain = dot_splitted_host.last(3).join('.')
cookie_domain = dot_splitted_host.last(3).join(".")
end
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/dispatch/cookies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def set_cookie_with_domain_and_tld

def set_cookie_with_domain_and_longer_tld
cookies[:user_name] = { value: "rizwanreza", domain: :all, tld_length: 4 }
head :ok
head :ok
end

def delete_cookie_with_domain_and_tld
Expand Down