Ignore accidental spaces around whitelabel URL

This commit is contained in:
Maikel Linke
2023-06-07 13:12:06 +10:00
parent 40111910b6
commit 1ebacf96ad
2 changed files with 7 additions and 0 deletions

View File

@@ -460,6 +460,7 @@ class Enterprise < ApplicationRecord
return if white_label_logo_link.blank?
white_label_logo_link.strip!
uri = URI(white_label_logo_link)
self.white_label_logo_link = "http://#{white_label_logo_link}" if uri.scheme.nil?
rescue URI::InvalidURIError

View File

@@ -332,6 +332,12 @@ describe Enterprise do
expect(e.white_label_logo_link).to eq "http://www.example.com"
end
it "ignores whitespace around the URL form copying and pasting" do
e = build(:enterprise, white_label_logo_link: ' www.example.com ')
expect(e).to be_valid
expect(e.white_label_logo_link).to eq "http://www.example.com"
end
it "does not validate if URL is invalid and can't be infered" do
e = build(:enterprise, white_label_logo_link: 'with spaces')
expect(e).to be_invalid