1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

rb_enc_str_asciionly_p expects T_STRING

This `str2` variable can be non-string (regexp etc.) but the previous
code passed it directly to rb_enc_str_asciionly_p(), which expects its
argument be a string.  Let's enforce that constraint.
This commit is contained in:
卜部昌平 2020-02-10 12:10:51 +09:00
parent a2845adb49
commit f83781c8c1

View file

@ -919,7 +919,7 @@ enc_compatible_latter(VALUE str1, VALUE str2, int idx1, int idx2)
if (isstr2 && RSTRING_LEN(str2) == 0)
return enc1;
isstr1 = RB_TYPE_P(str1, T_STRING);
if (isstr1 && RSTRING_LEN(str1) == 0)
if (isstr1 && isstr2 && RSTRING_LEN(str1) == 0)
return (rb_enc_asciicompat(enc1) && rb_enc_str_asciionly_p(str2)) ? enc1 : enc2;
if (!rb_enc_asciicompat(enc1) || !rb_enc_asciicompat(enc2)) {
return 0;