about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-05-05 21:11:19 +0200
committerGitHub <noreply@github.com>2018-05-05 21:11:19 +0200
commit8da4bf0f901d7b20f3ca7c6975a0d21a56fb735c (patch)
treec94a65d9cadf29b06acdfc6d90c608d6f6738ceb
parent80b23a6a85b4feeac732bc1612db4fe5ccdbac6d (diff)
4 profile fields max, store only 255 characters per name/value (#7348)
Fix #7303
-rw-r--r--app/models/account.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index a166fb474..72ba0398e 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -74,6 +74,7 @@ class Account < ApplicationRecord
   validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? }
   validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? }
   validates :note, length: { maximum: 160 }, if: -> { local? && will_save_change_to_note? }
+  validates :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? }
 
   # Timelines
   has_many :stream_entries, inverse_of: :account, dependent: :destroy
@@ -198,9 +199,11 @@ class Account < ApplicationRecord
   def fields_attributes=(attributes)
     fields = []
 
-    attributes.each_value do |attr|
-      next if attr[:name].blank?
-      fields << attr
+    if attributes.is_a?(Hash)
+      attributes.each_value do |attr|
+        next if attr[:name].blank?
+        fields << attr
+      end
     end
 
     self[:fields] = fields
@@ -269,8 +272,8 @@ class Account < ApplicationRecord
 
     def initialize(account, attr)
       @account = account
-      @name    = attr['name']
-      @value   = attr['value']
+      @name    = attr['name'].strip[0, 255]
+      @value   = attr['value'].strip[0, 255]
       @errors  = {}
     end