diff --git a/app/controllers/settings/verifications_controller.rb b/app/controllers/settings/verifications_controller.rb index cdb35f1ed2..9cc60ba2e8 100644 --- a/app/controllers/settings/verifications_controller.rb +++ b/app/controllers/settings/verifications_controller.rb @@ -19,13 +19,7 @@ class Settings::VerificationsController < Settings::BaseController def account_params params.require(:account).permit(:attribution_domains).tap do |params| - params[:attribution_domains] = params[:attribution_domains]&.lines&.map do |line| - line - .strip - .delete_prefix('http://') - .delete_prefix('https://') - .delete_prefix('*.') - end + params[:attribution_domains] = params[:attribution_domains].split if params[:attribution_domains] end end diff --git a/app/models/concerns/account/attribution_domains.rb b/app/models/concerns/account/attribution_domains.rb index 6b1479ff82..5f4d9afabf 100644 --- a/app/models/concerns/account/attribution_domains.rb +++ b/app/models/concerns/account/attribution_domains.rb @@ -4,7 +4,7 @@ module Account::AttributionDomains extend ActiveSupport::Concern included do - normalizes :attribution_domains, with: ->(arr) { arr.uniq } + normalizes :attribution_domains, with: ->(arr) { arr.filter_map { |str| str.to_s.strip.delete_prefix('http://').delete_prefix('https://').delete_prefix('*.').presence }.uniq } validates :attribution_domains, domain: true, length: { maximum: 100 }, if: -> { local? && will_save_change_to_attribution_domains? } end diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index db78abaccd..6c2bc52350 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -756,7 +756,9 @@ RSpec.describe Account do end describe 'attribution_domains' do - it { is_expected.to normalize(:attribution_domains).from(['example.com', 'example.com', 'example.net']).to(['example.com', 'example.net']) } + it { is_expected.to normalize(:attribution_domains).from(['example.com', ' example.com ', ' example.net ']).to(['example.com', 'example.net']) } + it { is_expected.to normalize(:attribution_domains).from(['https://example.com', 'http://example.net', '*.example.org']).to(['example.com', 'example.net', 'example.org']) } + it { is_expected.to normalize(:attribution_domains).from(['', ' ', nil]).to([]) } end end @@ -800,7 +802,7 @@ RSpec.describe Account do it { is_expected.to_not allow_values(account_note_over_limit).for(:note) } it { is_expected.to allow_values([], ['example.com'], (1..100).to_a).for(:attribution_domains) } - it { is_expected.to_not allow_values([''], ['@'], (1..101).to_a).for(:attribution_domains) } + it { is_expected.to_not allow_values(['example com'], ['@'], (1..101).to_a).for(:attribution_domains) } end context 'when account is remote' do