Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't tokenize string when counting characters #3873

Merged
merged 1 commit into from Dec 6, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions activemodel/lib/active_model/validations/length.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down