Skip to content

Commit 60a358c

Browse files
author
Anna
committed
force ASCII_8BIT encoding
1 parent 5413c67 commit 60a358c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ def initialize(name, default, sql_type = nil, null = true, sqlserver_options = {
6363
end
6464

6565
class << self
66-
# TODO: I think this has problems with ruby 2.0
66+
6767
def string_to_binary(value)
6868
"0x#{value.unpack("H*")[0]}"
6969
end
7070

7171
def binary_to_string(value)
72-
value =~ /[^[:xdigit:]]/ ? value : [value].pack('H*')
72+
if value.encoding != Encoding::ASCII_8BIT
73+
value = value.force_encoding(Encoding::ASCII_8BIT)
74+
end
75+
value
7376
end
7477

7578
end

0 commit comments

Comments
 (0)