Skip to content

Commit

Permalink
Fix warning for string conversion
Browse files Browse the repository at this point in the history
force_encoding seems to handle things better than in prior testing on older versions

Limited testing shows east asian width characters are properly represented
  • Loading branch information
Joe-Klauza committed Oct 27, 2023
1 parent 25fd0b6 commit 1c11fe8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions admin-interface/ext/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def center_utf8(length, padstr=' ')
end

def utf8
s = encode("UTF-16be", :invalid=>:replace, :replace=>"?").encode('UTF-8') #force_encoding('UTF-8')
s.strip # Don't strip; test that it can be stripped (else we fall back to encode())
s
# s = encode("UTF-16be", :invalid=>:replace, :replace=>"?").encode('UTF-8') #force_encoding('UTF-8')
# s.strip # Don't strip; test that it can be stripped (else we fall back to encode())
# s
force_encoding('UTF-8')
rescue => e
log("Failed to encode string as UTF-8: #{self.inspect}", level: :warn)
encode('UTF-8', invalid: :replace, undef: :replace)
Expand Down
1 change: 1 addition & 0 deletions admin-interface/lib/server-query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'socket'
require_relative 'logger'
require_relative '../ext/string'

# https://developer.valvesoftware.com/wiki/Server_queries
# https://apidock.com/ruby/Array/pack
Expand Down

0 comments on commit 1c11fe8

Please sign in to comment.