fix the regexp used to valide user's website
This commit is contained in:
parent
2f36b7eae1
commit
e43799134c
|
@ -4,7 +4,7 @@ class UserProfile < ActiveRecord::Base
|
||||||
# This is not very picky about most DNS labels (the bits between the
|
# This is not very picky about most DNS labels (the bits between the
|
||||||
# periods), but isn't taking much guff from the TLD. No leading
|
# periods), but isn't taking much guff from the TLD. No leading
|
||||||
# digit, and no hyphens unless IDN.
|
# digit, and no hyphens unless IDN.
|
||||||
WEBSITE_REGEXP = /(^$)|((^(http|https):\/\/)?([a-z0-9][a-z0-9-]*\.)+([a-z][a-z0-9]+|xn--[a-z0-9-]+)(\/.*)?$)/ix
|
WEBSITE_REGEXP = /(^$)|(^(https?:\/\/)?([a-z0-9][a-z0-9-]*\.)+([a-z][a-z0-9]+|xn--[a-z0-9-]+)(\/.*)?$)/i
|
||||||
|
|
||||||
validates :bio_raw, length: { maximum: 3000 }
|
validates :bio_raw, length: { maximum: 3000 }
|
||||||
validates :website, format: { with: WEBSITE_REGEXP }, allow_blank: true, if: Proc.new { |c| c.new_record? || c.website_changed? }
|
validates :website, format: { with: WEBSITE_REGEXP }, allow_blank: true, if: Proc.new { |c| c.new_record? || c.website_changed? }
|
||||||
|
|
|
@ -59,6 +59,7 @@ describe UserProfile do
|
||||||
|
|
||||||
it "ensures website is valid" do
|
it "ensures website is valid" do
|
||||||
expect(Fabricate.build(:user_profile, user: user, website: "http://https://google.com")).not_to be_valid
|
expect(Fabricate.build(:user_profile, user: user, website: "http://https://google.com")).not_to be_valid
|
||||||
|
expect(Fabricate.build(:user_profile, user: user, website: "http://discourse.productions")).to be_valid
|
||||||
expect(Fabricate.build(:user_profile, user: user, website: "https://google.com")).to be_valid
|
expect(Fabricate.build(:user_profile, user: user, website: "https://google.com")).to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue