Fix coderange calculation in String#b
Leave the new coderange unknown if the original encoding is not ASCII-compatible. Non-ASCII-compatible encoding strings with valid or broken coderange can end up as ascii-only. Fixes 9a8f6e392fbd ("Cheaply derive code range for String#b return value", 2022-07-25).
This commit is contained in:
parent
1c14e406d3
commit
5b0396473b
2
string.c
2
string.c
@ -10771,6 +10771,7 @@ rb_str_b(VALUE str)
|
||||
}
|
||||
str_replace_shared_without_enc(str2, str);
|
||||
|
||||
if (rb_enc_asciicompat(STR_ENC_GET(str))) {
|
||||
// BINARY strings can never be broken; they're either 7-bit ASCII or VALID.
|
||||
// If we know the receiver's code range then we know the result's code range.
|
||||
int cr = ENC_CODERANGE(str);
|
||||
@ -10786,6 +10787,7 @@ rb_str_b(VALUE str)
|
||||
ENC_CODERANGE_CLEAR(str2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return str2;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user