diff options
author | Soutaro Matsumoto <matsumoto@soutaro.com> | 2020-09-11 14:34:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-11 14:34:10 +0900 |
commit | f0ddbd502c1d6912cec9a91997966ba659e347c1 (patch) | |
tree | babd8255e60b285492ffb440e6fa22755b64de69 /string.c | |
parent | 0d78390bfb9d87ac7ee192115216882e09c50a06 (diff) |
Let String#slice! return nil (#3533)
Returns `nil` instead of an empty string when non-integer number is given (to make it 2.7 compatible).
Notes
Notes:
Merged-By: soutaro <matsumoto@soutaro.com>
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -4961,7 +4961,10 @@ rb_str_slice_bang(int argc, VALUE *argv, VALUE str) return Qnil; case Qfalse: beg = NUM2LONG(indx); - goto num_index; + if (!(p = rb_str_subpos(str, beg, &len))) return Qnil; + if (!len) return Qnil; + beg = p - RSTRING_PTR(str); + goto subseq; default: goto num_index; } |