提交 5ff71ac9 编写于 作者: I Ian Young

Don't tokenize string when counting characters

上级 cf6ccf0e
......@@ -6,7 +6,6 @@ class LengthValidator < EachValidator
MESSAGES = { :is => :wrong_length, :minimum => :too_short, :maximum => :too_long }.freeze
CHECKS = { :is => :==, :minimum => :>=, :maximum => :<= }.freeze
DEFAULT_TOKENIZER = lambda { |value| value.split(//) }
RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :tokenizer, :too_short, :too_long]
def initialize(options)
......@@ -36,7 +35,7 @@ def check_validity!
end
def validate_each(record, attribute, value)
value = (options[:tokenizer] || DEFAULT_TOKENIZER).call(value) if value.kind_of?(String)
value = options[:tokenizer].call(value) if value.kind_of?(String) && options[:tokenizer].present?
CHECKS.each do |key, validity_check|
next unless check_value = options[key]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册