X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/a39c645602f9d27b7927500c93890f4d7d79620e..61c3d97a8ad2891bef0a2eeaa0d60e625b6c2ef2:/app/validators/whitespace_validator.rb?ds=sidebyside diff --git a/app/validators/whitespace_validator.rb b/app/validators/whitespace_validator.rb index d177df92a..333ad0e05 100644 --- a/app/validators/whitespace_validator.rb +++ b/app/validators/whitespace_validator.rb @@ -1,11 +1,11 @@ class WhitespaceValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless options.fetch(:leading, true) - record.errors[attribute] << (options[:message] || I18n.t("validations.leading_whitespace")) if value =~ /\A\s/ + record.errors[attribute] << (options[:message] || I18n.t("validations.leading_whitespace")) if /\A\s/.match?(value) end unless options.fetch(:trailing, true) - record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if value =~ /\s\z/ + record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if /\s\z/.match?(value) end end end