diff options
author | Joshua Wood <josh@joshuawood.net> | 2022-11-17 01:59:35 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-17 10:59:35 +0100 |
commit | daf6f3453e2a37db3d9a8362d64106b6c7cf0763 (patch) | |
tree | b6fb6551791d7057c01b90471dd3f477fafdb9a6 /app | |
parent | cbb0153bd0945a6aaf612850e1fa6c788336c01b (diff) |
Handle links with no href in VerifyLinkService (#20741)
Before this change, the following error would cause VerifyAccountLinksWorker to fail: NoMethodError: undefined method `downcase' for nil:NilClass [PROJECT_ROOT]/app/services/verify_link_service.rb:31 :in `block in link_back_present?`
Diffstat (limited to 'app')
-rw-r--r-- | app/services/verify_link_service.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/app/services/verify_link_service.rb b/app/services/verify_link_service.rb index 0a39d7f26..7496fe2d5 100644 --- a/app/services/verify_link_service.rb +++ b/app/services/verify_link_service.rb @@ -28,7 +28,7 @@ class VerifyLinkService < BaseService links = Nokogiri::HTML(@body).xpath('//a[contains(concat(" ", normalize-space(@rel), " "), " me ")]|//link[contains(concat(" ", normalize-space(@rel), " "), " me ")]') - if links.any? { |link| link['href'].downcase == @link_back.downcase } + if links.any? { |link| link['href']&.downcase == @link_back.downcase } true elsif links.empty? false @@ -38,6 +38,8 @@ class VerifyLinkService < BaseService end def link_redirects_back?(test_url) + return false if test_url.blank? + redirect_to_url = Request.new(:head, test_url, follow: false).perform do |res| res.headers['Location'] end |