Hi,

In message "Re: [ruby-core:18600] [Bug #566] String encoding error messages are inconsistent"
    on Mon, 15 Sep 2008 15:50:17 +0900, Michael Selig <redmine / ruby-lang.org> writes:

|Please compare:
|"abc".encode("UTF-16BE") << "abc"
|==> EncodingCompatibilityError: incompatible character encodings: UTF-16BE and US-ASCII
|and:
|"abc".encode("UTF-16BE") =~ /abc/
|==> ArgumentError: incompatible encoding regexp match (US-ASCII regexp with UTF-16BE string)
|
|also handling of broken (illegal) string encodings is not consistent:
|"abc".force_encoding("UTF-16BE") =~ /abc/
|==> ArgumentError: broken UTF-16BE string
|and:
|"abc".force_encoding("UTF-16BE") == "abc"
|==> false (no error)
|and:
|"abc".encode("UTF-16BE").count("b".force_encoding("UTF-16BE"))
|==> ArgumentError: invalid byte sequence in UTF-16BE

I am not sure what you mean by "inconsistent".  What are your ideal
messages (or behavior) for each case?

							matz.