]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/3138'
authorTom Hughes <tom@compton.nu>
Wed, 17 Mar 2021 18:16:15 +0000 (18:16 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 17 Mar 2021 18:16:15 +0000 (18:16 +0000)
app/validators/characters_validator.rb
app/validators/whitespace_validator.rb

index 837e3e6cc89628fe130b52b09816fc73341f54e2..13d08ca55e06e1079f9b44c39ba429e854a06916 100644 (file)
@@ -3,7 +3,7 @@ class CharactersValidator < ActiveModel::EachValidator
   INVALID_URL_CHARS = "/;.,?%#".freeze
 
   def validate_each(record, attribute, value)
-    record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_characters")) if /[#{INVALID_CHARS}]/o.match?(value)
-    record.errors[attribute] << (options[:message] || I18n.t("validations.url_characters", :characters => INVALID_URL_CHARS)) if options[:url_safe] && /[#{INVALID_URL_CHARS}]/o.match?(value)
+    record.errors.add(attribute, options[:message] || I18n.t("validations.invalid_characters")) if /[#{INVALID_CHARS}]/o.match?(value)
+    record.errors.add(attribute, options[:message] || I18n.t("validations.url_characters", :characters => INVALID_URL_CHARS)) if options[:url_safe] && /[#{INVALID_URL_CHARS}]/o.match?(value)
   end
 end
index 3032c109eb03c1bae7bbc6fcc16b3546c055dd73..6453742c21fbadf0e08b77434f6a98d1e724f457 100644 (file)
@@ -1,6 +1,6 @@
 class WhitespaceValidator < ActiveModel::EachValidator
   def validate_each(record, attribute, value)
-    record.errors[attribute] << (options[:message] || I18n.t("validations.leading_whitespace")) if !options.fetch(:leading, true) && /\A\s/.match?(value)
-    record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if !options.fetch(:trailing, true) && /\s\z/.match?(value)
+    record.errors.add(attribute, options[:message] || I18n.t("validations.leading_whitespace")) if !options.fetch(:leading, true) && /\A\s/.match?(value)
+    record.errors.add(attribute, options[:message] || I18n.t("validations.trailing_whitespace")) if !options.fetch(:trailing, true) && /\s\z/.match?(value)
   end
 end