mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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 9a8f6e392f
("Cheaply derive code range for String#b return
value", 2022-07-25).
This commit is contained in:
parent
1c14e406d3
commit
5b0396473b
1 changed files with 16 additions and 14 deletions
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…
Add table
Add a link
Reference in a new issue