diff options
author | Starfall <us@starfall.systems> | 2021-03-04 23:55:42 -0600 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2021-03-04 23:55:42 -0600 |
commit | fe6381b9acc28cd610b032160de2952e1fdefc86 (patch) | |
tree | ad1ba10427d5d792d3ba797479528f01e51404a5 /app/validators | |
parent | 033b1b5b900babc9b068ddad0ae644c5f15e9ffe (diff) | |
parent | f4abf8e7829c6a5b952dea6fb9ad01b6b3601f95 (diff) |
Merge remote-tracking branch 'glitchsoc/main' into main
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/blacklisted_email_validator.rb | 4 | ||||
-rw-r--r-- | app/validators/email_mx_validator.rb | 11 | ||||
-rw-r--r-- | app/validators/note_length_validator.rb | 2 | ||||
-rw-r--r-- | app/validators/status_length_validator.rb | 9 | ||||
-rw-r--r-- | app/validators/unique_username_validator.rb | 2 | ||||
-rw-r--r-- | app/validators/unreserved_username_validator.rb | 5 |
6 files changed, 22 insertions, 11 deletions
diff --git a/app/validators/blacklisted_email_validator.rb b/app/validators/blacklisted_email_validator.rb index 20a1587cc..1ca73fdcc 100644 --- a/app/validators/blacklisted_email_validator.rb +++ b/app/validators/blacklisted_email_validator.rb @@ -2,11 +2,11 @@ class BlacklistedEmailValidator < ActiveModel::Validator def validate(user) - return if user.valid_invitation? + return if user.valid_invitation? || user.email.blank? @email = user.email - user.errors.add(:email, I18n.t('users.blocked_email_provider')) if blocked_email? + user.errors.add(:email, :blocked) if blocked_email? end private diff --git a/app/validators/email_mx_validator.rb b/app/validators/email_mx_validator.rb index ef1554494..9f70a1469 100644 --- a/app/validators/email_mx_validator.rb +++ b/app/validators/email_mx_validator.rb @@ -4,16 +4,19 @@ require 'resolv' class EmailMxValidator < ActiveModel::Validator def validate(user) + return if user.email.blank? + domain = get_domain(user.email) - if domain.nil? - user.errors.add(:email, I18n.t('users.invalid_email')) + if domain.blank? + user.errors.add(:email, :invalid) else ips, hostnames = resolve_mx(domain) + if ips.empty? - user.errors.add(:email, I18n.t('users.invalid_email_mx')) + user.errors.add(:email, :unreachable) elsif on_blacklist?(hostnames + ips) - user.errors.add(:email, I18n.t('users.blocked_email_provider')) + user.errors.add(:email, :blocked) end end end diff --git a/app/validators/note_length_validator.rb b/app/validators/note_length_validator.rb index 5ff6df6df..7ea2bb3e5 100644 --- a/app/validators/note_length_validator.rb +++ b/app/validators/note_length_validator.rb @@ -2,7 +2,7 @@ class NoteLengthValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - record.errors.add(attribute, I18n.t('statuses.over_character_limit', max: options[:maximum])) if too_long?(value) + record.errors.add(attribute, :too_long, message: I18n.t('statuses.over_character_limit', max: options[:maximum]), count: options[:maximum]) if too_long?(value) end private diff --git a/app/validators/status_length_validator.rb b/app/validators/status_length_validator.rb index 92ee5e643..dcbc4a41a 100644 --- a/app/validators/status_length_validator.rb +++ b/app/validators/status_length_validator.rb @@ -2,6 +2,13 @@ class StatusLengthValidator < ActiveModel::Validator MAX_CHARS = (ENV['MAX_TOOT_CHARS'] || 500).to_i + URL_PATTERN = %r{ + (?: + (#{Twitter::TwitterText::Regex[:valid_url_preceding_chars]}) + (#{FetchLinkCardService::URL_PATTERN}) + ) + }iox + URL_PLACEHOLDER = "\1#{'x' * 23}" def validate(status) return unless status.local? && !status.reblog? @@ -28,7 +35,7 @@ class StatusLengthValidator < ActiveModel::Validator return '' if @status.text.nil? @status.text.dup.tap do |new_text| - new_text.gsub!(FetchLinkCardService::URL_PATTERN, 'x' * 23) + new_text.gsub!(URL_PATTERN, URL_PLACEHOLDER) new_text.gsub!(Account::MENTION_RE, '@\2') end end diff --git a/app/validators/unique_username_validator.rb b/app/validators/unique_username_validator.rb index f87eb06ba..09c8fadb5 100644 --- a/app/validators/unique_username_validator.rb +++ b/app/validators/unique_username_validator.rb @@ -4,7 +4,7 @@ class UniqueUsernameValidator < ActiveModel::Validator def validate(account) - return if account.username.nil? + return if account.username.blank? normalized_username = account.username.downcase normalized_domain = account.domain&.downcase diff --git a/app/validators/unreserved_username_validator.rb b/app/validators/unreserved_username_validator.rb index 634ceb06e..974f3ba62 100644 --- a/app/validators/unreserved_username_validator.rb +++ b/app/validators/unreserved_username_validator.rb @@ -3,9 +3,10 @@ class UnreservedUsernameValidator < ActiveModel::Validator def validate(account) @username = account.username - return if @username.nil? - account.errors.add(:username, I18n.t('accounts.reserved_username')) if reserved_username? + return if @username.blank? + + account.errors.add(:username, :reserved) if reserved_username? end private |