-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
If an error occurs during authentication (in my case the host I connect from is not permitted), the error message is attempted to be decoded.
However, at that time @charset is not yet defined:
Uncaught exception: undefined method `encoding' for nil:NilClass
C:/Ruby/2.3.0/lib/ruby/gems/2.3.0/gems/ruby-mysql-2.9.14/lib/mysql/protocol.rb:502:in `read'
C:/Ruby/2.3.0/lib/ruby/gems/2.3.0/gems/ruby-mysql-2.9.14/lib/mysql/protocol.rb:178:in `authenticate'
C:/Ruby/2.3.0/lib/ruby/gems/2.3.0/gems/ruby-mysql-2.9.14/lib/mysql.rb:116:in `connect'
C:/Ruby/2.3.0/lib/ruby/gems/2.3.0/gems/ruby-mysql-2.9.14/lib/mysql.rb:50:in `new'ruby-mysql/lib/mysql/protocol.rb
Line 502 in 44520a1
| message.force_encoding(@charset.encoding) |
As you can see from the stacktrace the line in method authenticate is 178. However, @charset is not defined before line 185:
ruby-mysql/lib/mysql/protocol.rb
Lines 178 to 189 in 44520a1
| init_packet = InitialPacket.parse read | |
| @server_info = init_packet.server_version | |
| @server_version = init_packet.server_version.split(/\D/)[0,3].inject{|a,b|a.to_i*100+b.to_i} | |
| @thread_id = init_packet.thread_id | |
| client_flags = CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_TRANSACTIONS | CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION | |
| client_flags |= CLIENT_CONNECT_WITH_DB if db | |
| client_flags |= flag | |
| @charset = charset | |
| unless @charset | |
| @charset = Charset.by_number(init_packet.server_charset) | |
| @charset.encoding # raise error if unsupported charset | |
| end |
I was able to help myself by modifying line 502 to:
message.force_encoding(Mysql::Charset.by_number(33).encoding)where 33 is the numeric representation of UTF-8:
ruby-mysql/lib/mysql/charset.rb
Line 63 in 44520a1
| [ 33, "utf8", "utf8_general_ci", true ], |
Metadata
Metadata
Assignees
Labels
No labels