mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #4022 from gschlager/importer-patch
Don't try to import invalid websites
This commit is contained in:
commit
dedbb59321
@ -1,8 +1,10 @@
|
|||||||
class UserProfile < ActiveRecord::Base
|
class UserProfile < ActiveRecord::Base
|
||||||
belongs_to :user, inverse_of: :user_profile
|
belongs_to :user, inverse_of: :user_profile
|
||||||
|
|
||||||
|
WEBSITE_REGEXP = /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,9}(([0-9]{1,5})?\/.*)?$)/ix
|
||||||
|
|
||||||
validates :bio_raw, length: { maximum: 3000 }
|
validates :bio_raw, length: { maximum: 3000 }
|
||||||
validates :website, format: { with: /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,9}(([0-9]{1,5})?\/.*)?$)/ix }, allow_blank: true
|
validates :website, format: { with: WEBSITE_REGEXP }, allow_blank: true
|
||||||
validates :user, presence: true
|
validates :user, presence: true
|
||||||
before_save :cook
|
before_save :cook
|
||||||
after_save :trigger_badges
|
after_save :trigger_badges
|
||||||
|
@ -306,8 +306,8 @@ class ImportScripts::Base
|
|||||||
User.transaction do
|
User.transaction do
|
||||||
u.save!
|
u.save!
|
||||||
if bio_raw.present? || website.present? || location.present?
|
if bio_raw.present? || website.present? || location.present?
|
||||||
u.user_profile.bio_raw = bio_raw if bio_raw.present?
|
u.user_profile.bio_raw = bio_raw[0..2999] if bio_raw.present?
|
||||||
u.user_profile.website = website if website.present?
|
u.user_profile.website = website unless website.blank? || website !~ UserProfile::WEBSITE_REGEXP
|
||||||
u.user_profile.location = location if location.present?
|
u.user_profile.location = location if location.present?
|
||||||
u.user_profile.save!
|
u.user_profile.save!
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user