Make String#chomp! raise ArgumentError for 2+ arguments if string is empty
String#chomp! returned nil without checking the number of passed arguments in this case.
This commit is contained in:
parent
c42e4a38e9
commit
0d53dba7ce
2
string.c
2
string.c
@ -9689,7 +9689,7 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
|
|||||||
{
|
{
|
||||||
VALUE rs;
|
VALUE rs;
|
||||||
str_modifiable(str);
|
str_modifiable(str);
|
||||||
if (RSTRING_LEN(str) == 0) return Qnil;
|
if (RSTRING_LEN(str) == 0 && argc < 2) return Qnil;
|
||||||
rs = chomp_rs(argc, argv);
|
rs = chomp_rs(argc, argv);
|
||||||
if (NIL_P(rs)) return Qnil;
|
if (NIL_P(rs)) return Qnil;
|
||||||
return rb_str_chomp_string(str, rs);
|
return rb_str_chomp_string(str, rs);
|
||||||
|
@ -587,6 +587,8 @@ CODE
|
|||||||
assert_equal("foo", s.chomp!("\n"))
|
assert_equal("foo", s.chomp!("\n"))
|
||||||
s = "foo\r"
|
s = "foo\r"
|
||||||
assert_equal("foo", s.chomp!("\n"))
|
assert_equal("foo", s.chomp!("\n"))
|
||||||
|
|
||||||
|
assert_raise(ArgumentError) {String.new.chomp!("", "")}
|
||||||
ensure
|
ensure
|
||||||
$/ = save
|
$/ = save
|
||||||
$VERBOSE = verbose
|
$VERBOSE = verbose
|
||||||
|
Loading…
x
Reference in New Issue
Block a user