Bug #17011
closedBigDecimal .to_s should not use ASCII-8BIT
Description
BigDecimal#to_s
returns a String
in ASCII-8BIT encoding. This is inconvenient in situations where the encoding determines program behaviour, since ASCII-8BIT is a special encoding that implies binary (non-textual) data, it can require an explicit conversion.
BigDecimal#to_s
should either use the currently active encoding, or it should use US-ASCII like Integer#to_s
.
Recreation script:
# encoding: utf-8
Encoding.default_internal = Encoding::UTF_8
Encoding.default_external = Encoding::UTF_8
require 'bigdecimal'
puts BigDecimal('2').to_s.encoding
Desired output: US-ASCII
or UTF-8
Actual output: ASCII-8BIT
Updated by david.drakard (David Drakard) about 4 years ago
- Description updated (diff)
Updated by byroot (Jean Boussier) about 4 years ago
I submitted a PR for it: https://github.com/ruby/ruby/pull/3291
Updated by nobu (Nobuyoshi Nakada) about 4 years ago
- Description updated (diff)
Could you submit this to https://github.com/ruby/bigdecimal?
Updated by byroot (Jean Boussier) about 4 years ago
Actually, it's already been fixed upstream: https://github.com/ruby/bigdecimal/pull/160
Maybe the Ruby spec part of my PR is still useful. I'll submit it to https://github.com/ruby/spec
Updated by Eregon (Benoit Daloze) about 4 years ago
How should we proceed to include that fix in CRuby master?
Updated by Eregon (Benoit Daloze) about 4 years ago
- Status changed from Open to Closed
- Assignee set to nobu (Nobuyoshi Nakada)
@nobu (Nobuyoshi Nakada) picked that fix in https://github.com/ruby/ruby/commit/6a826eb4b08484cb3b6279da905f5b9e03e0df5f
(details at https://github.com/ruby/spec/pull/778#issuecomment-655420419)
Thanks!