Skip to content

Commit

Permalink
Merge pull request #8547 from printercu/patch-1
Browse files Browse the repository at this point in the history
fix for messages in invalid encoding from db-drivers

Conflicts:
	activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
	activerecord/test/cases/connection_adapters/abstract_adapter_test.rb
  • Loading branch information
rafaelfranca committed Jan 2, 2015
1 parent a953f7f commit 8bf2f1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,12 @@ def extract_limit(sql_type) # :nodoc:
end

def translate_exception_class(e, sql)
message = "#{e.class.name}: #{e.message}: #{sql}"
begin
message = "#{e.class.name}: #{e.message}: #{sql}"
rescue Encoding::CompatibilityError
message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql}"
end

@logger.error message if @logger
exception = translate_exception(e, message)
exception.set_backtrace e.backtrace
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ def test_select_methods_passing_a_relation
test "type_to_sql returns a String for unmapped types" do
assert_equal "special_db_type", @connection.type_to_sql(:special_db_type)
end

def test_log_invalid_encoding
assert_raise ActiveRecord::StatementInvalid do
@connection.send :log, "SELECT 'ы' FROM DUAL" do
raise 'ы'.force_encoding(Encoding::ASCII_8BIT)
end
end
end
end

class AdapterTestWithoutTransaction < ActiveRecord::TestCase
Expand Down

0 comments on commit 8bf2f1b

Please sign in to comment.