docbrown/app/services/users/safe_remote_profile_image_url.rb
Andy Zhao 84d931136e
Fix bug where OAuth signups were not pulling in OAuth provider's profile image (#14711)
* Use regex to replace with https

* Refactor a bit

* Update logic to handle edge cases

* url being nil
* url not a valid URL (weak validation, checks for starting
string of http)

* Add new test case for http to https conversion
2021-09-14 22:13:16 -04:00

13 lines
340 B
Ruby

module Users
module SafeRemoteProfileImageUrl
# Basic check for nil and blank URLs, alongside likely incomplete URLs, such as just "image.jpg".
def self.call(url)
if url&.start_with?("http")
url.sub!("http://", "https://")
url
else
Users::ProfileImageGenerator.call
end
end
end
end