Skip to content

Commit

Permalink
replace all instances of "ends_with?" with "end_with?" (mastodon#15745)
Browse files Browse the repository at this point in the history
The "ends_with?" method is just a Rails alias of Ruby's "end_with?" method.
Using the latter makes the code less brittle.
  • Loading branch information
jtracey authored and chrisguida committed Feb 26, 2022
1 parent 2479782 commit 6ce3b9d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ def pagination_url(max_id: nil, min_id: nil)
end

def media_requested?
request.path.split('.').first.ends_with?('/media') && !tag_requested?
request.path.split('.').first.end_with?('/media') && !tag_requested?
end

def replies_requested?
request.path.split('.').first.ends_with?('/with_replies') && !tag_requested?
request.path.split('.').first.end_with?('/with_replies') && !tag_requested?
end

def tag_requested?
request.path.split('.').first.ends_with?(Addressable::URI.parse("/tagged/#{params[:tag]}").normalize)
request.path.split('.').first.end_with?(Addressable::URI.parse("/tagged/#{params[:tag]}").normalize)
end

def cached_filtered_status_page
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def raise_not_found
private

def https_enabled?
Rails.env.production? && !request.path.start_with?('/health') && !request.headers["Host"].ends_with?(".onion")
Rails.env.production? && !request.path.start_with?('/health') && !request.headers["Host"].end_with?(".onion")
end

def authorized_fetch_mode?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/media_proxy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def redownload!
end

def version
if request.path.ends_with?('/small')
if request.path.end_with?('/small')
:small
else
:original
Expand Down
4 changes: 2 additions & 2 deletions app/lib/webfinger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ def webfinger_request(url)
end

def standard_url
if @domain.ends_with? ".onion"
if @domain.end_with? ".onion"
"http://#{@domain}/.well-known/webfinger?resource=#{@uri}"
else
"https://#{@domain}/.well-known/webfinger?resource=#{@uri}"
end
end

def host_meta_url
if @domain.ends_with? ".onion"
if @domain.end_with? ".onion"
"http://#{@domain}/.well-known/host-meta"
else
"https://#{@domain}/.well-known/host-meta"
Expand Down
4 changes: 2 additions & 2 deletions lib/action_dispatch/cookie_jar_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module CookieJarExtensions
# Monkey-patch ActionDispatch to serve secure cookies to Tor Hidden Service
# users. Otherwise, ActionDispatch would drop the cookie over HTTP.
def write_cookie?(*)
request.host.ends_with?('.onion') || super
request.host.end_with?('.onion') || super
end
end
end
Expand All @@ -17,7 +17,7 @@ def write_cookie?(*)
module Rack
module SessionPersistedExtensions
def security_matches?(request, options)
request.host.ends_with?('.onion') || super
request.host.end_with?('.onion') || super
end
end
end
Expand Down

0 comments on commit 6ce3b9d

Please sign in to comment.