Skip to content

Commit 2224072

Browse files
committed
Fix String#encode and convert fallback value into String with #to_str
1 parent 147c42a commit 2224072

File tree

3 files changed

+2
-16
lines changed

3 files changed

+2
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Compatibility:
3838
* Fix `IO#{autoclose=,autoclose?}` and raise `IOError` when io is closed (@andrykonchin).
3939
* Fix `Thread#{thread_variable_get,thread_variable_set,thread_variable?,key?,[],[]=,fetch}` and convert a non-String/Symbol thread-local variable name to String using `#to_str` (@andrykonchin).
4040
* Fix formatting in `Exception#full_message` when `RuntimeError` is not handled and `highlight` option is specified (@andrykonchin).
41+
* Fix `String#encode` and convert fallback values into String using `#to_str` (@andrykonchin).
4142

4243
Performance:
4344

spec/tags/core/string/encode_tags.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
fails:String#encode given the fallback option given a hash calls to_str on the returned value
2-
fails:String#encode given the fallback option given a hash does not call to_s on the returned value
31
fails:String#encode given the fallback option given a hash raises an error if the key is not present in the hash
42
fails:String#encode given the fallback option given a hash raises an error if the value is itself invalid
53
fails:String#encode given the fallback option given an object not responding to [] raises an error
6-
fails:String#encode given the fallback option given a proc calls to_str on the returned value
7-
fails:String#encode given the fallback option given a proc does not call to_s on the returned value
84
fails:String#encode given the fallback option given a proc raises an error if the returned value is itself invalid
9-
fails:String#encode given the fallback option given a lambda calls to_str on the returned value
10-
fails:String#encode given the fallback option given a lambda does not call to_s on the returned value
115
fails:String#encode given the fallback option given a lambda raises an error if the returned value is itself invalid
12-
fails:String#encode given the fallback option given a method calls to_str on the returned value
13-
fails:String#encode given the fallback option given a method does not call to_s on the returned value
146
fails:String#encode given the fallback option given a method raises an error if the returned value is itself invalid
157
fails:String#encode when passed options normalizes newlines with cr_newline option
168
fails:String#encode when passed options normalizes newlines with crlf_newline option
17-
fails:String#encode! given the fallback option given a hash calls to_str on the returned value
18-
fails:String#encode! given the fallback option given a hash does not call to_s on the returned value
199
fails:String#encode! given the fallback option given a hash raises an error if the key is not present in the hash
2010
fails:String#encode! given the fallback option given a hash raises an error if the value is itself invalid
2111
fails:String#encode! given the fallback option given an object not responding to [] raises an error
22-
fails:String#encode! given the fallback option given a proc calls to_str on the returned value
23-
fails:String#encode! given the fallback option given a proc does not call to_s on the returned value
2412
fails:String#encode! given the fallback option given a proc raises an error if the returned value is itself invalid
25-
fails:String#encode! given the fallback option given a lambda calls to_str on the returned value
26-
fails:String#encode! given the fallback option given a lambda does not call to_s on the returned value
2713
fails:String#encode! given the fallback option given a lambda raises an error if the returned value is itself invalid
28-
fails:String#encode! given the fallback option given a method calls to_str on the returned value
29-
fails:String#encode! given the fallback option given a method does not call to_s on the returned value
3014
fails:String#encode! given the fallback option given a method raises an error if the returned value is itself invalid

src/main/ruby/truffleruby/core/string.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ def encode!(to = undefined, from = undefined, **options)
419419
(_, fallback_enc_from, fallback_enc_to, error_bytes, _) = ec.primitive_errinfo
420420
rep = fallback[error_bytes.force_encoding(fallback_enc_from)]
421421
raise ec.last_error unless rep
422+
rep = Truffle::Type.rb_convert_type rep, String, :to_str
422423
dest << rep.encode(fallback_enc_to)
423424
status = ec.primitive_convert src, dest, nil, nil
424425
end

0 commit comments

Comments
 (0)