]> cat aescling's git repositories - mastodon.git/commitdiff
Fix admin validation being too strict about usernames (#10449)
authorEugen Rochko <eugen@zeonfederated.com>
Sat, 6 Apr 2019 15:53:17 +0000 (17:53 +0200)
committerGitHub <noreply@github.com>
Sat, 6 Apr 2019 15:53:17 +0000 (17:53 +0200)
* Fix admin validation being too strict about usernames

Fix #10446

* Strip Setting.site_contact_username consistently throughout the codebase

app/controllers/home_controller.rb
app/controllers/shares_controller.rb
app/models/concerns/account_finder_concern.rb
app/presenters/instance_presenter.rb
app/validators/existing_username_validator.rb

index b5d6460f9fc1a2dfca8a904a661a5db55b924e89..d1bd0601e91afe5eed6402dc7a2a773c6e92b0d6 100644 (file)
@@ -50,7 +50,7 @@ class HomeController < ApplicationController
       push_subscription: current_account.user.web_push_subscription(current_session),
       current_account: current_account,
       token: current_session.token,
-      admin: Account.find_local(Setting.site_contact_username),
+      admin: Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')),
     }
   end
 
index 9ef1e07491d0d2660074b4ca4473e9f2c72ec0b4..af605b98f701fce34dfbc5f15815d48134f5f888 100644 (file)
@@ -21,7 +21,7 @@ class SharesController < ApplicationController
       push_subscription: current_account.user.web_push_subscription(current_session),
       current_account: current_account,
       token: current_session.token,
-      admin: Account.find_local(Setting.site_contact_username),
+      admin: Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')),
       text: text,
     }
   end
index 7e3bbde097799a711f6921125b629ede25e4b8d2..0ac49cc126d69ab2a42b2c967f2d65de01371564 100644 (file)
@@ -13,7 +13,7 @@ module AccountFinderConcern
     end
 
     def representative
-      find_local(Setting.site_contact_username.gsub(/\A@/, '')) || Account.local.find_by(suspended: false)
+      find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')) || Account.local.find_by(suspended: false)
     end
 
     def find_local(username)
index 74c5ed12936ac9f911f8caa499560ba84aa575ef..f3a73209afe56658c78372d3f2b272e5fbcdd10b 100644 (file)
@@ -13,7 +13,7 @@ class InstancePresenter
   )
 
   def contact_account
-    Account.find_local(Setting.site_contact_username.gsub(/\A@/, ''))
+    Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, ''))
   end
 
   def user_count
index 4388a0c98365f5fe8488360f1a13386777dc8bfb..b31d098273a7ee146bfcfd9c246f1e6fe629c6e4 100644 (file)
@@ -5,16 +5,10 @@ class ExistingUsernameValidator < ActiveModel::EachValidator
     return if value.blank?
 
     if options[:multiple]
-      missing_usernames = value.split(',').map { |username| username unless Account.find_local(username) }.compact
+      missing_usernames = value.split(',').map { |username| username.strip.gsub(/\A@/, '') }.map { |username| username unless Account.find_local(username) }.compact
       record.errors.add(attribute, I18n.t('existing_username_validator.not_found_multiple', usernames: missing_usernames.join(', '))) if missing_usernames.any?
     else
-      record.errors.add(attribute, I18n.t('existing_username_validator.not_found')) unless Account.find_local(value)
+      record.errors.add(attribute, I18n.t('existing_username_validator.not_found')) unless Account.find_local(value.strip.gsub(/\A@/, ''))
     end
   end
-
-  private
-
-  def valid_html?(str)
-    Nokogiri::HTML.fragment(str).to_s == str
-  end
 end