diff --git a/string.c b/string.c index 9da5708964..cfad52d2e3 100644 --- a/string.c +++ b/string.c @@ -9689,7 +9689,7 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str) { VALUE rs; str_modifiable(str); - if (RSTRING_LEN(str) == 0) return Qnil; + if (RSTRING_LEN(str) == 0 && argc < 2) return Qnil; rs = chomp_rs(argc, argv); if (NIL_P(rs)) return Qnil; return rb_str_chomp_string(str, rs); diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 42553cba82..1c7e085630 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -587,6 +587,8 @@ CODE assert_equal("foo", s.chomp!("\n")) s = "foo\r" assert_equal("foo", s.chomp!("\n")) + + assert_raise(ArgumentError) {String.new.chomp!("", "")} ensure $/ = save $VERBOSE = verbose