diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-08-24 10:31:17 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2022-11-24 18:24:42 -0800 |
commit | 571d21fd4a2e877f49b4ff918832bda9a5e8f91c (patch) | |
tree | fea4111dba639d534d975c63c3689c1f9a9b7e0e /test/ruby | |
parent | c6330cd32b7d02b4603080a2c53d64be9e05773c (diff) | |
download | ruby-571d21fd4a2e877f49b4ff918832bda9a5e8f91c.tar.gz |
Make String#rstrip{,!} raise Encoding::CompatibilityError for broken coderange
It's questionable whether we want to allow rstrip to work for strings
where the broken coderange occurs before the trailing whitespace and
not after, but this approach is probably simpler, and I don't think
users should expect string operations like rstrip to work on broken
strings.
In some cases, this changes rstrip to raise
Encoding::CompatibilityError instead of ArgumentError. However, as
the problem is related to an encoding issue in the receiver, and due
not due to an issue with an argument, I think
Encoding::CompatibilityError is the more appropriate error.
Fixes [Bug #18931]
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_string.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 4add7dfe2f..66db5b565d 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -2817,6 +2817,11 @@ CODE assert_equal("\u3042", s5) assert_raise(Encoding::CompatibilityError) { S("\u3042".encode("ISO-2022-JP")).rstrip! } + assert_raise(Encoding::CompatibilityError) { S("abc \x80 ".force_encoding('UTF-8')).rstrip! } + assert_raise(Encoding::CompatibilityError) { S("abc\x80 ".force_encoding('UTF-8')).rstrip! } + assert_raise(Encoding::CompatibilityError) { S("abc \x80".force_encoding('UTF-8')).rstrip! } + assert_raise(Encoding::CompatibilityError) { S("\x80".force_encoding('UTF-8')).rstrip! } + assert_raise(Encoding::CompatibilityError) { S(" \x80 ".force_encoding('UTF-8')).rstrip! } end def test_lstrip |