From: "sawa (Tsuyoshi Sawada)" Date: 2013-11-15T00:04:21+09:00 Subject: [ruby-core:58339] [ruby-trunk - Feature #9111] Encoding-free String comparison Issue #9111 has been updated by sawa (Tsuyoshi Sawada). Following nobu's suggestion, I came up with the following several possibilities: When two strings with different encodings are to be compared by `String#<=>`, then one of the following options should be taken: * Raise a Warning message * Raise an error * Convert one of the strings to the other one. I am not sure which option would be the best, but feel the feature should not be left as is now. ---------------------------------------- Feature #9111: Encoding-free String comparison https://bugs.ruby-lang.org/issues/9111#change-42937 Author: sawa (Tsuyoshi Sawada) Status: Open Priority: Normal Assignee: Category: Target version: =begin Currently, strings with the same content but with different encodings count as different strings. This causes strange behaviour as below (noted in StackOverflow question http://stackoverflow.com/questions/19977788/strange-behavior-in-packed-ruby-strings#19978206): [128].pack("C") # => "\x80" [128].pack("C") == "\x80" # => false Since `[128].pack("C")` has the encoding ASCII-8BIT and `"\x80"` (by default) has the encoding UTF-8, the two strings are not equal. Also, comparison of strings with different encodings may end up with a messy, unintended result. I suggest that the comparison `String#<=>` should not be based on the respective encoding of the strings, but all the strings should be internally converted to UTF-8 for the purpose of comparison. =end -- http://bugs.ruby-lang.org/