Bug #566: String encoding error messages are inconsistent
http://redmine.ruby-lang.org/issues/show/566

Author: Michael Selig
Status: Open, Priority: Normal

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


----------------------------------------
http://redmine.ruby-lang.org