* 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
13 lines
340 B
Ruby
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
|