Actions
Bug #16649
closedObject with [] method doesn't work as String#encode's fallback
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.8.0dev (2020-02-23T15:28:34Z master f88d209bb7) [x86_64-linux]
Backport:
Description
String#encode
document says fallback can be a Hash, a Proc, a Method or an object which has []
method.
Sets the replacement string by the given object for undefined character. The object should be a Hash, a Proc, a Method, or an object which has [] method
https://docs.ruby-lang.org/en/2.7.0/String.html#method-i-encode
But actually an object with []
does not work.
Reproduce:
class C
def [](str)
'!'
end
end
str = "\u00b7\u2014"
p str.encoding # => #<Encoding:UTF-8>
# It works
p str.encode("Windows-31J", fallback: C.new.method(:[]))
# => "!!"
# It does not work
p str.encode("Windows-31J", fallback: C.new)
# => U+00B7 from UTF-8 to Windows-31J (Encoding::UndefinedConversionError)
Updated by nobu (Nobuyoshi Nakada) over 4 years ago
- Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED
Updated by nobu (Nobuyoshi Nakada) over 4 years ago
- Status changed from Open to Closed
Applied in changeset git|8b6e2685a4b7c7de905f7ed60c02ef85e0724754.
Fixed symbol misused as ID
rb_funcallv_public
and rb_respond_to
require an ID
, not a
Symbol
. [Bug #16649]
Updated by naruse (Yui NARUSE) over 4 years ago
- Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE
ruby_2_7 fa48a26d886d86469a0075d91d152252e9fc0c8c.
Updated by usa (Usaku NAKAMURA) over 3 years ago
- Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE to 2.5: REQUIRED, 2.6: DONE, 2.7: DONE
backported into ruby_2_6 at r67901.
Actions
Like0
Like0Like0Like0Like0