Skip to content

Commit

Permalink
Handle quoting multibyte strings with newlines.
Browse files Browse the repository at this point in the history
[#999 state:committed]
  • Loading branch information
NZKoz committed Sep 24, 2008
1 parent ec39711 commit c75e711
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -2085,7 +2085,7 @@ def expand_range_bind_variables(bind_vars) #:nodoc:
end end


def quote_bound_value(value) #:nodoc: def quote_bound_value(value) #:nodoc:
if value.respond_to?(:map) && !value.is_a?(String) if value.respond_to?(:map) && !value.is_a?(String) && !value.is_a?(ActiveSupport::Multibyte::Chars)
if value.respond_to?(:empty?) && value.empty? if value.respond_to?(:empty?) && value.empty?
connection.quote(nil) connection.quote(nil)
else else
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/finder_test.rb
Expand Up @@ -387,6 +387,14 @@ def test_bind_string
assert_equal ActiveRecord::Base.connection.quote(''), bind('?', '') assert_equal ActiveRecord::Base.connection.quote(''), bind('?', '')
end end


def test_bind_string_with_nl
assert_equal ActiveRecord::Base.connection.quote("a\nb"), bind('?', "a\nb")
end

def test_bind_mb_string_with_nl
assert_equal ActiveRecord::Base.connection.quote("a\nb"), bind('?', "a\nb".chars)
end

def test_bind_record def test_bind_record
o = Struct.new(:quoted_id).new(1) o = Struct.new(:quoted_id).new(1)
assert_equal '1', bind('?', o) assert_equal '1', bind('?', o)
Expand Down

0 comments on commit c75e711

Please sign in to comment.